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:
- 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.
- 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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…