How to communicat with serial/usb from Chrome extension?

292 views
Skip to first unread message

Christian LeMoussel

unread,
Jul 7, 2021, 11:47:59 AM7/7/21
to Chromium Extensions
I am working on developing a Chrome extension that uses the Web Serial API, to communicate with ESP32 board that is connected via USB.
I did some tests but the ''navigator.serial' object doesn't seem to be accessible from a Chrome extension. However, it's unclear to me how to reference it. 

Deco

unread,
Jul 7, 2021, 11:49:30 AM7/7/21
to Christian LeMoussel, Chromium Extensions
 You can use the USB API to accomplish this: https://developer.chrome.com/docs/extensions/reference/usb/

Thanks,
Deco

On Wed, 7 Jul 2021, 16:48 Christian LeMoussel, <cnh...@gmail.com> wrote:
I am working on developing a Chrome extension that uses the Web Serial API, to communicate with ESP32 board that is connected via USB.
I did some tests but the ''navigator.serial' object doesn't seem to be accessible from a Chrome extension. However, it's unclear to me how to reference it. 

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/4fa3985b-ccc3-45f6-a1b0-621bb10b4e6en%40chromium.org.

Jackie Han

unread,
Jul 7, 2021, 12:51:33 PM7/7/21
to Christian LeMoussel, Chromium Extensions
the ''navigator.serial' object doesn't seem to be accessible from a Chrome extension

navigator.serial can work in standard web pages(Chrome 89+), so it can work in all extension pages except (service) worker.

On Wed, Jul 7, 2021 at 11:48 PM Christian LeMoussel <cnh...@gmail.com> wrote:
I am working on developing a Chrome extension that uses the Web Serial API, to communicate with ESP32 board that is connected via USB.
I did some tests but the ''navigator.serial' object doesn't seem to be accessible from a Chrome extension. However, it's unclear to me how to reference it. 

--

Christian LeMoussel

unread,
Jul 8, 2021, 1:13:48 AM7/8/21
to Chromium Extensions, Jackie Han, Chromium Extensions, Christian LeMoussel
I agree with you that   navigator.serial can work in standard web pages(Chrome 89+.  For example: serialTerminal.com
What do you mean that it can work in all extension pages?

I tested with the use of Content scripts or the creation of an IFrame with the call to JS code (Web Accessible Resources) but each time navigator.serial is undefined.
Here my  V3 manifest.json
manifest.json

Christian LeMoussel

unread,
Jul 8, 2021, 1:14:41 AM7/8/21
to Chromium Extensions, decklin...@gmail.com, Chromium Extensions, Christian LeMoussel
USB API is part of the deprecated Chrome Apps platform.

Jackie Han

unread,
Jul 8, 2021, 3:18:38 AM7/8/21
to Christian LeMoussel, Chromium Extensions
What do you mean that it can work in all extension pages?
Web pages are "http or https" pages.
Extension pages is "chrome-extension://extension_id/my_page_in_extension".
Both web pages and extension pages can use "navigator.serial".

If you use content scripts, that means your code run in web page context.
Web Serial API is available only in secure contexts (HTTPS). so it can't work in http pages(navigator.serial is undefined).

PS: json file can't support comment statements(//).

Christian LeMoussel

unread,
Jul 8, 2021, 3:52:11 AM7/8/21
to Chromium Extensions, Jackie Han, Chromium Extensions, Christian LeMoussel
Rhooo... I tested from an HTTP site.
Unless I am mistaken, this information is not indicated in the Web Serial API documentation.
I will resume all my tests with an HTTPS site.

Thanks a lot for your help
Reply all
Reply to author
Forward
0 new messages