简体   繁体   English

Chrome 扩展程序:如何使用串行端口(现在应用程序正在淘汰)?

[英]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.目标:我正在尝试编写一个可以从我的浏览器与 Arduino 的 COM 端口通信的小“东西”。

Issue : My first attempt is to write an extension.问题:我的第一次尝试是编写扩展。 Therefore I am requesting permission for serial in my manifest file.因此,我在清单文件中请求serial权限。 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.通过开发人员模式加载未打包的扩展时,我收到以下错误: '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 .我在这里看到packaged app是一个过时的术语,我想它们只是指Chrome app Now unfortunately it seems that Chrome is also discontinuing these Chrome apps as discussed here .现在不幸的是,Chrome 似乎也停止了这些 Chrome 应用程序,正如 这里讨论的那样

Question : So how should I access the serial functionality of Chrome apps/extensions/whatever new name you come up with?问题:那么我应该如何访问 Chrome 应用程序/扩展程序/您想出的任何新名称的serial功能?

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.您可以继续编写 chrome 应用程序并使用 chrome.serial API,但使用 NW.js 作为应用程序的运行时。 It supports the Chrome App APIs.它支持 Chrome 应用程序 API。 Essentially you just write your Chrome App but instead of opening it in Chrome you open it in NW.js executable.本质上,您只需编写 Chrome 应用程序,而不是在 Chrome 中打开它,而是在 NW.js 可执行文件中打开它。

https://nwjs.io/ https://nwjs.io/

Or you could use a Node.js package such as serialport to access your COM port或者您可以使用 Node.js 包(例如 serialport)来访问您的 COM 端口

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

In this case you could write it as either NW.js app, or an Electron app.在这种情况下,您可以将其编写为 NW.js 应用程序或 Electron 应用程序。 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.您可以访问节点模块生态系统以及 Chromium - Chrome 网络浏览器的开源部分,因此您仍然可以执行您想要的所有 HTML/JavaScript/CSS。

https://github.com/electron/electron https://github.com/electron/electron

This is also one of the suggested paths from Google: https://developer.chrome.com/apps/migration#native这也是 Google 建议的路径之一: https : //developer.chrome.com/apps/migration#native

"Web Serial API", navigator.serial , may be the best way looking forward. “Web Serial API”, navigator.serial ,可能是最好的展望方式。 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.自 chrome 77 以来,它已在chrome://flags#enable-experimental-web-platform-features标志后面可用。它将进入 Origin 试验 80-82,然后在 83 中发货。

Web Serial API allows serial interface directly from a progressive web app. Web Serial API 允许直接来自渐进式 Web 应用程序的串行接口。 There is a good tutorial at https://codelabs.developers.google.com/codelabs/web-serial/#0 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.您可能应该避免使用仅在 chrome 应用程序中可用的旧版chrome.serial ,因为从 2020 年 6 月开始,将不再支持 Windows、Mac 和 Linux 上的 Chrome 应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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