🌐 Serial & Fieldbus ⏱ 10 min read • Updated 2026-10-26

Web Serial API Architecture: Driverless Browser-to-UART Hardware Communication

Engineering guide to the W3C Web Serial API (`navigator.serial`), asynchronous ReadableStream/WritableStream byte pipelines, Modbus RTU inter-frame silence timers, and hardware flow control in Chromium browsers.
Interactive Workstation Available: Test the protocols and algorithms covered in this guide live in your browser using TCP/UDP & Serial Port Tester.
Launch TCP/UDP & Serial Port Tester ➔

Historically, accessing a physical RS-232 or RS-485 COM port from a computer required installing native C++/C# desktop applications, Java RXTX applets, or background localhost websocket agents. The W3C Web Serial API (`navigator.serial`), natively integrated into Chromium-based browsers (Google Chrome, Microsoft Edge, Opera), bridges the browser security sandbox directly to the operating system's hardware UART and USB-CDC drivers (FTDI FT232R, Silicon Labs CP210x, WCH CH340, and Prolific PL2303).

1. Security Model & User-Gesture Port Permission

To prevent malicious websites from silently scanning local hardware peripherals, the Web Serial API enforces three strict security invariants:

  1. Secure Context Requirement: navigator.serial is only exposed on HTTPS origins (`https://gogg.gg`) or `http://localhost`.
  2. Transient User Activation: Calling await navigator.serial.requestPort() must be triggered directly by a physical user gesture (such as a mouse click on a "Connect COM Port" button).
  3. Per-Origin Permission Grant: Once the engineer selects a COM port from the native browser chooser dialog, the port handle is bound exclusively to that origin and can be opened with custom UART framing parameters.

2. Opening UART Ports & Configuring Framing Parameters

async function openIndustrialSerialPort() {
  const port = await navigator.serial.requestPort();
  await port.open({
    baudRate: 115200,      // Standard: 9600, 19200, 38400, 57600, 115200
    dataBits: 8,           // 8 for Modbus RTU / binary; 7 for Modbus ASCII
    stopBits: 1,           // 1 or 2 stop bits
    parity: "none",        // "none", "even" (standard Modbus RTU default), or "odd"
    bufferSize: 16384,     // 16 KB OS ring buffer to prevent overrun on bursts
    flowControl: "none"    // "none" or "hardware" (RTS/CTS)
  });
  return port;
}

3. Asynchronous Stream Chunking & Frame Reassembly

When reading from port.readable.getReader(), the operating system USB-serial driver delivers incoming bytes in arbitrary Uint8Array chunks (often 1 to 64 bytes at a time depending on the FTDI latency timer). A single 25-byte Modbus RTU response may arrive split across three separate reader.read() calls!

Therefore, industrial web applications must never assume that one read() call equals one complete protocol packet. Instead, incoming chunks are appended into a contiguous accumulation buffer combined with an Inter-Frame Silence Watchdog Timer:

Baud Rate (bps) 11-Bit Character Time ($t_{\text{char}}$) Theoretical Modbus $t_{3.5}$ Silence Recommended Browser Silence Timer
9,600 bps $1.146\text{ ms}$ $4.01\text{ ms}$ $15\text{ ms}$ – $20\text{ ms}$ (accounts for USB 16 ms latency timer)
19,200 bps $0.573\text{ ms}$ $2.01\text{ ms}$ $10\text{ ms}$ – $15\text{ ms}$
38,400 bps $0.286\text{ ms}$ $1.75\text{ ms}$ (fixed minimum) $8\text{ ms}$ – $12\text{ ms}$
115,200 bps $0.095\text{ ms}$ $1.75\text{ ms}$ (fixed minimum) $5\text{ ms}$ – $10\text{ ms}$

4. Controlling RS-232 Modem Signals (DTR / RTS)

The Web Serial API exposes direct control over hardware modem lines via await port.setSignals({ dataTerminalReady: true, requestToSend: false }) and status inspection via await port.getSignals() (`clearToSend`, `dataCarrierDetect`, `dataSetReady`, `ringIndicator`). This allows browser tools to reset microcontrollers, trigger optical isolators powered by DTR/RTS pins, and diagnose hardware handshaking lines without an oscilloscope.

5. Clean Stream Release & Port Teardown

Calling port.close() while a ReadableStreamDefaultReader or WritableStreamDefaultWriter lock is still active throws a TypeError: Cannot close a locked stream. Production code must cancel the active reader (`await reader.cancel()`), release both locks (`reader.releaseLock()`, `writer.releaseLock()`), and await the read loop termination before invoking await port.close().

Frequently Asked Questions (FAQ)

Q. Which web browsers support the Web Serial API for direct COM port access?

Desktop Chromium-based browsers—including Google Chrome (v89+), Microsoft Edge (v89+), and Opera—support the Web Serial API natively on Windows, macOS, Linux, and ChromeOS.

Q. Why does my USB-to-RS485 adapter split a 20-byte response into two separate chunks 16 ms apart?

FTDI USB-serial drivers default to a 16 ms USB bulk transfer latency timer. Your stream parser must accumulate incoming Uint8Array chunks until the expected frame length is reached or an idle timer expires.

Q. Why do I get 'NetworkError: Failed to open serial port' when clicking Connect?

On Windows, a COM port is an exclusive OS resource. Another application (such as GX Works, PuTTY, or another browser tab) currently holds the COM port open; close the other program and retry.

Q. Does Web Serial API transmit any serial data to external cloud servers?

No. The Web Serial API communicates strictly between the local browser tab's JavaScript memory and the local OS kernel's serial port driver with zero network traffic.

📘 Complete Engineering Guides Directory (16 Technical Articles)