简体   繁体   English

Web 串行 api,无需用户手势即可打开端口

[英]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.

相关问题 Web Serial API - Uncaught (in promise) DOMException: Failed to open serial port / required member baudRate is undefined - Web Serial API - Uncaught (in promise) DOMException: Failed to open serial port / required member baudRate is undefined 什么是“必须处理用户手势才能显示权限请求”。 Chrome Web 串行 API 中的错误消息? - What is "Must be handling a user gesture to show a permission request." errror message in Chrome Web Serial API? 访问 web worker 中的串口 - Access serial port in web worker Web应用程序通过串行端口进行通信 - Web application to communicate over serial port Web应用程序需要与串行端口通信 - Web app needs to communicate with serial port 在网页上显示串口数据 - Display Serial port data on web page Web 音频 api - AudioContext 不允许启动。 它必须在页面上的用户手势后恢复(或创建) - Web audio api - The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page Web Serial API - 自动读取 - Web Serial API - Automatically read Web 页面全屏打开,无需用户交互 - Web page open in full screen without user interaction 我的Web应用程序如何与串行端口通信 - How can my web app communicate with serial port
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM