Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
197 views
in Technique[技术] by (71.8m points)

navigator.serial in Chrome extension

I'm trying to make use of the serial interface to drive a thermal receipt printer within Chrome. After I've started a little PoC based on the Chrome.Serial API and recognized the phase-out, I'm now trying to move over to navigator.serial. I have been able to establish a connection if I do it outside of a Chrome extension. However, when I try to select the interface from the extension like this const port = await navigator.serial.requestPort();, I get one of the following errors:

  1. If I trigger the code via a button on the extension, I'm told that the user hasn't selected anything (seems to be the same message that is thrown on cancel): Uncaught (in promise) NotFoundError: No port selected by the user.
  2. If I try to automatically trigger the selection, I'm told that a user gestures is required: Uncaught (in promise) SecurityError: Failed to execute 'requestPort' on 'Serial': Must be handling a user gesture to show a permission request.

I've also tried to use debug mode and the console to manually pair the extension with the serial interface once, so I could continue to use getPorts. But I haven't been able to display the selection dialog even once from the Chrome extension. Can anybody help me here?

question from:https://stackoverflow.com/questions/65861626/navigator-serial-in-chrome-extension

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...