简体   繁体   中英

Chrome extension: how to use serial port (now that apps are sunsetting)?

Aim : I am attempting to write a little "thing" that can talk from my browser to the COM port of an Arduino.

Issue : My first attempt is to write an extension. Therefore I am requesting permission for serial in my manifest file. When loading the unpackaged extension via developer mode I receive the following error: 'serial' is only allowed for packaged apps, but this is a extension.

I see here that packaged app is an outdated term and I guess they just mean Chrome app . Now unfortunately it seems that Chrome is also discontinuing these Chrome apps as discussed here .

Question : So how should I access the serial functionality of Chrome apps/extensions/whatever new name you come up with?

You could continue on the same path of writing a chrome app and using the chrome.serial API, but use NW.js as the runtime of your app. It supports the Chrome App APIs. Essentially you just write your Chrome App but instead of opening it in Chrome you open it in NW.js executable.

https://nwjs.io/

Or you could use a Node.js package such as serialport to access your COM port

https://github.com/EmergingTechnologyAdvisors/node-serialport

In this case you could write it as either NW.js app, or an Electron app. Electron is quite popular lately. You have access to the node module ecosystem and also Chromium - open source part of Chrome web browser so you can still do all the HTML/JavaScript/CSS you want.

https://github.com/electron/electron

This is also one of the suggested paths from Google: https://developer.chrome.com/apps/migration#native

"Web Serial API", navigator.serial , may be the best way looking forward. It has been available behind the #enable-experimental-web-platform-features flag in chrome://flags since chrome 77. It is due to go to Origin trials 80-82 then ship in 83.

Web Serial API allows serial interface directly from a progressive web app. There is a good tutorial at https://codelabs.developers.google.com/codelabs/web-serial/#0

You should probably avoid the older chrome.serial , available only in chrome apps, because from June 2020 Chrome Apps on Windows, Mac, and Linux will no longer be supported.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM