In web serial api, I am able to open ports on button click. Is there any way to open port once the port is connected ? onconnect event does not open port, asking for user gesture...I need automatic open for mass production...
Asked
Active
Viewed 869 times
1 Answers
1
As indicated in https://web.dev/serial/#open-port, requestPort()
requires a user gesture such as touch or mouse click. However once you have a port, you can open()
one on subsequent page load without any user gesture.
// Get all serial ports the user has previously granted the website access to.
const ports = await navigator.serial.getPorts();
// Assuming the first one is the one you want to open...
const port = ports[0];
// Open serial port without user gesture.
await port.open({ baudRate: 9600 });

François Beaufort
- 4,843
- 3
- 29
- 38
-
Thanks for the reply..... I realised that it certainly requires a user gesture. – Sibin Dec 02 '21 at 13:29