[英]Web serial api , Port open without user gesture
In web serial api, I am able to open ports on button click.在 web 串行 api 中,我可以通过单击按钮打开端口。 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...
onconnect 事件未打开端口,要求用户手势...我需要自动打开以进行量产...
As indicated in https://web.dev/serial/#open-port , requestPort()
requires a user gesture such as touch or mouse click.如https://web.dev/serial/#open-port中所示,
requestPort()
需要用户手势,例如触摸或鼠标单击。 However once you have a port, you can open()
one on subsequent page load without any user gesture.但是,一旦有了端口,您就可以在后续页面加载时
open()
一个,而无需任何用户手势。
// 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 });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.