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...
1 Answer
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 });
1 Comment
Sibin
Thanks for the reply..... I realised that it certainly requires a user gesture.