The Serial API follows a security model similar to Web Bluetooth and WebUSB to mitigate risks such as malicious firmware installation or device exploitation. To use the API, your application must adhere to the following requirements:
1. Secure Origin
The page must be served from a secure origin (HTTPS) to prevent network-based code injection.
2. Permission Model
Access to devices is not automatic. You must use requestPort() to trigger a user-facing prompt. The user must actively select a specific device to grant access. This prevents 'drive-by' attacks where a site attempts to access hardware without user interaction.
3. Cross-Origin Restrictions
Cross-origin iframes are prohibited from using the Serial API unless the embedding page explicitly grants permission via Feature Policy.
4. Privacy and Device Identification
Once a user grants access to a device, the site may be able to access identifiers such as:
- Vendor and Product IDs (for USB/Bluetooth devices).
- Serial numbers or MAC addresses.
- Data returned via serial commands.
Because the user agent cannot inspect the opaque data sent over the serial line, the primary privacy defense is the permission model, which ensures a site cannot proactively enumerate available devices without user consent (similar to the File Picker API).