1

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 1

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 });
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the reply..... I realised that it certainly requires a user gesture.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.