How to access USB device in chrome? - javascript

I need a web application which is used to copy the files from usb drive. I can write a java applet to copy the files from usb drive, but chrome will not support applet any more. Could you please suggest any alternative to this?
I need a web application not a chrome app.

Chrome 61+ has an implementation of the WebUSB API
This would not let you issue a command to the OS/File system to, for example:
copy file://some_file_location/myfile.txt to file://USB_DRIVE/some_folder/myfile.txt
Chrome would need to read the files and write to the device directly. In other words the browser would be copying the files by reading them (see below) and then writing to the USB device. This would probably be quite slow and unfeasible for large files.
Your options to read local files are:
To run chrome with the --allow-file-access-from-files flag. This is a security issue/risk, and users would need to visit your site/application with this already on.
Use the File and FileReader, or the non-standard FileSystem APIs along with a input type="file" or drag & drop
Neither of these may be applicable to your problem/solution.

I'd recommend using node.js , its cross platform and can access usb ports from web browser..
Usb Library: https://www.npmjs.com/package/usb
Proof : How to send data to USB device in node.js using libusb
Hope this helps

Related

Debugging from Web - Embedded boards

So excited to asks experts on this platform. I don't know where my question fits but anyone familiar with ARM mbed or dev.ti.com?
Let me give you a clue. On these website they provide an online IDE (just like desktop version) on which you can build an "Embedded Software" and download, run and Debug on some target board like (TIVA C, STM32 etc.) connected to PC. As far as i know javascript on web page doesn't have any access to local machine. So how does it access computer ports and computer drivers etc?
WEB Experts please give me a clue like how browser is allowed to access local computer resources??
In most cases, you're correct - Javascript running in your browser does not have access to many of the resources needed for reprogramming and debugging a development board.
However, there are a few ways to work around this:
1. Build development boards that can work with the hardware APIs the browser already allows access to.
This usually involves using APIs in unexpected ways. The integrated debug firmware on all mbed boards emulates a USB disk drive. The user can download the firmware file from the mbed site and then copy it onto the disk drive to install the firmware on the development board.
There are also some more creative (mis)uses of hardware APIs. For example, this Chibitronics board relies on the browser sending the new firmware via audio output. I have also heard about - but cannot find a suitable link to - an example of repurposing the U2F protocol to do double duty as a firmware update mechanism.
Because this approach repurposes existing APIs, it is generally widely supported, but requires extra work on the device side to fit a square peg into a round hole.
2. Install a native application/extension that accesses hardware and allows the website to access the hardware through the extension.
This is the approach used by TI Cloud Tools, Arduino Create, and Codebender. Once a user has installed a companion application, that application allows the website to access anything that a normal IDE would be able to access.
In a sense, this approach is very similar to building a native application with a very cloud-centric UI.
3. Extend browsers to add new hardware APIs that can be used to program development boards.
The WebBluetooth and WebUSB draft standards add new APIs to allow Javascript to access BLE and USB devices directly, which can then be used to communicate directly with connected USB debug hardware or BLE bootloaders.
micro:bit is currently testing a beta program that uses WebUSB to directly program and communicate with micro:bit boards.
These APIs are only implemented in Chrome, so they are not a universal solution. Additionally, due to security restrictions and driver issues, not all existing hardware is compatible with WebUSB.
As far as i know javascript on web page doesn't have any access to local machine. So how does it access computer ports and computer drivers etc?
You can access your local machine through a server. For example to ask it for a certain file or to run some commands/code through an API you define.
How browser is allowed to access local computer resources?
The browser is a program on your machine. The programming language(s) in which the browser was built provides interfaces to communicate with your system on a low level.
It's worth mentioning that the browser and the web application it renders are not the same and do not communicate in the same way with your system.

Possible to remotely access files on mobile devices using HTML5/JS?

I have a file sharing web app online where I want people to be able to remotely access and upload files from their mobile devices without a client, but clientless via HTML5/JS, to our servers.
I have seem remote support companies log in to client devices just using browser with clients permission.
Thank you for your time
Robert
I have a file sharing web app online where I want people to be able to remotely access and upload files from their mobile devices without a client, but clientless via HTML5/JS, to our servers.
This isn't possible.
Web applications cannot access files that haven't been explicitly selected by the user. Additionally, they cannot store files on the user's system without a download, and they cannot do anything at all unless they are active in a browser -- they cannot run in the background.
Web applications running on mobile (i.e, Android or iOS) devices are even more limited. They typically cannot interact with most files on the system. For instance, web applications running on iOS can only upload photos from the user's photo library, not arbitrary files.
I have seem remote support companies log in to client devices just using browser with clients permission.
Either you were mistaken, or something else was going on. For instance, a client application may have been previously installed.
I'm not following exactly what you mean. If you already have the service, that means that you can just create a form with a filefield to upload whatever you want, the size limit is only imposed by your web server (apache/nginx/whatever) and your backend service.
You can complicate things a little bit using HTML5 web storage (that's what MEGA uses) but I can't give you any specifics if you don't explain a bit more in depth what you want to achieve.

Detect if a USB device is plugged in Javascript from browser

Is there Javascript based mechanism with which i can detect, through a browser, that a user has a specific usb device plugged in?
For security reasons, JavaScript in web browsers provides only restricted access to computer resources. It is not possible to store files in an arbitrary folder, start applications or communicate with a USB device.
But there are some exceptions :
In legacy browsers such as IE6 ~ IE8 you can use ActiveX objects or Java applets to achieve this .
Use a chrome.usb API .
Write a browser plugin using NPAPI , (Here, it is not for long though)
Your javascript code is sand boxed and therefore cannot access system resources such as usb devices.
I think the only way to access the USB devices would be to write a browser plugin.
How to get USB devices List from Browser

How can I access to USB stick from website?

I'm planning to make a login system by USB, so if you put in a USB-drive and open a specific webpage, the website asks the USB-drive for the code (e.g. by a JavaScript file, a redirect or something like that).
The problem is, because of sandboxing, you can't load or redirect to local files. I don't know a solution for this problem. Can you guys help me? I don't need specific code, just an example or something in that way.
Maybe you can read up on USB-HID. Wikipedia:
The USB human interface device class (USB HID class) is a part of the USB specification for computer peripherals: it specifies a device class (a type of computer hardware) for human interface devices such as keyboards, mice, game controllers and alphanumeric display devices.
Here are some references:
USB HID (Human Interface Device)
node-hid - Access USB HID devices from node.js
DepthJS: 'Allows any web page to interact with the Microsoft Kinect using Javascript'.
A related Stackoverflow question:
Write data to USB HID using Javascript, HTML5, or any cross platform language (supports Android)
One other possibility is to check out the Chrome HID (Human Interface Device) APIs:
Interacting with USB HID devices from web apps – via Chrome Apps, see below
Relevant Chrome API docs
Please note that for the time being, you cannot interact directly with the USB device (i.e. you cannot access any WebAPI offering that kind of fine-grained control).
Building a Chrome App (different from a Chrome Extension) may help; This article may point you in the right direction, since it also provides sample code.
The only way I can think of is putting a html file on the usb stick that essentially generates some sort of login token and gives you a link or a form to a login processor. You can then access the webpage by opening the local file first which will redirect you to the actual webpage.
This local script may include a javascript from the server to get some challenge-response-data which it hashes somehow (perhaps in combination with a password) and puts it into the form data.
Web PKI authentication from Modern Browsers may be achieved by using Browser Extension. One such extension is Signer.Digital browser extension. Use below Javascript promises from the APIs provided by Signer.Digital extension.
SignerDigital.getSelectedCertificate() to register user's certificate
SignerDigital.signHash(hash) to sign token at browser and verify at server
For all Javascript APIs refer to SO Answer https://stackoverflow.com/a/63173083/9659885
Disclaimer : I work for a company supporting the application below
Hello, you may try to use Nexu open-source application for communication with smartcards or USB tokens. It also support PKCS 12 keystores.
For example, the application is connected to the DSS webpage on the website of European Commission : see the link.

JavaScript Filewriter in FireFox

I need to allow users of my Web App to save files in their local file system after working on an editor implemented with javascript ( to work on a browser )
I heard about FileWriter API in HTML5, but not sure if it is supported in any of the Firefox versions, particularly FireFox 5.
Does anyone have any alternatives apart from Server side processing to allow users to save files into their local filesystem ( ofcourse with a permission from the user ) in FireFox. As I read Google Chrome supports FileWriter API though am not been able to make it work yet.
FileWriter is a Google working draft
Firefox team is working on implementing FileWriter also:
https://bugzilla.mozilla.org/show_bug.cgi?id=557540
No, Firefox does not support FileWriter, and the standardization of this API was abandoned (1, 2). http://www.w3.org/TR/file-writer-api/ now states:
Work on this document has been discontinued and it should not be referenced or used as a basis for implementation.
It seems that that API didn't even provide the feature you seem to be looking for:
The API doesn't give you access to the local file system, nor is the sandbox really a section of the file system. Instead, it is a virtualized file system that looks like a full-fledged file system to the web app. It does not necessarily have a relationship to the local file system outside the browser.
What this means is that a web app and a desktop app cannot share the same file at the same time. The API does not let your web app reach outside the browser to files that desktop apps can also work on.
You could use localStorage or IndexedDB to store the data client-side, albeit not in an arbitrary file the user can select via filepicker.
You could write an extension that provides the necessary API to content JS. As of 2015, it's unclear which technology you should use for that.
Downloadify (Adobe Flash initiating a download) is also often mentioned when discussing this. This thread mentions an alternative based on data: URIs.

Categories