Overview of Serial Parsers
webserial-core transform a stream of raw Uint8Array chunks into structured values of type T. To use a parser, pass it to the parser property within SerialDeviceOptions.website·Indexed 29 days ago
https://webserial.devA library for serial communication in the browser. It provides a unified interface via AbstractSerialDevice<T> and supports multiple transport layers including the native Web Serial API, WebUSB (via WebUsbProvider), Web Bluetooth (via WebBluetoothProvider), and WebSockets (via WebSocketProvider). The library includes built-in parsers to transform raw Uint8Array chunks into structured values.
webserial-core transform a stream of raw Uint8Array chunks into structured values of type T. To use a parser, pass it to the parser property within SerialDeviceOptions.The createBluetoothProvider() factory function returns a SerialProvider that uses the Web Bluetooth API over GATT to emulate a serial connection. It specifically implements the Nordic UART Service (NUS), making it compatible with nRF52 series, ESP32 BLE UART, HC-08 / AT-09 BLE modules, and any firmware advertising the NUS service.
Supported NUS UUIDs:
6e400001-b5a3-f393-e0a9-e50e24dcca9e6e400002-b5a3-f393-e0a9-e50e24dcca9e6e400003-b5a3-f393-e0a9-e50e24dcca9eSerialError class is a structured error wrapper used in webserial-core to categorize serial communication failures using a typed code and optional context. Note: This is part of the v1 legacy API, which is currently on security fixes only.import { SerialError, SerialErrorCode } from "webserial-core";The createBluetoothProvider() function returns a SerialProvider that uses the Web Bluetooth API over GATT to emulate a serial connection. It specifically implements the Nordic UART Service (NUS) with the following UUIDs:
6e400001-b5a3-f393-e0a9-e50e24dcca9e6e400002-b5a3-f393-e0a9-e50e24dcca9e6e400003-b5a3-f393-e0a9-e50e24dcca9eCompatible hardware includes nRF52 series, ESP32 BLE UART, HC-08 / AT-09 BLE modules, or any firmware announcing the NUS service.
import { createBluetoothProvider } from "webserial-core";SerialDevice class. Instead, create a new class that extends AbstractSerialDevice<T> to align with the new v2 architecture.// Example: Extend AbstractSerialDevice in v2
class MyDevice extends AbstractSerialDevice<MyDeviceOptions> {
// Implementation details
}WebBluetoothProvider to communicate with BLE UART modules that implement the Nordic UART Service (NUS) over GATT. Compatible hardware includes any device advertising the NUS service UUID 6e400001-b5a3-f393-e0a9-e50e24dcca9e, such as nRF52840, nRF52832, ESP32 (with Arduino BLE UART sketch), and BLE-to-UART modules like HC-08, AT-09, or HM-10.WebBluetoothProvider allows communication with BLE UART modules via the Nordic UART Service (NUS) over GATT. It is compatible with any device advertising the NUS service UUID 6e400001-b5a3-f393-e0a9-e50e24dcca9e, including nRF52840/nRF52832 (NUS firmware), ESP32 (Arduino BLE UART), and HC-08, AT-09, or HM-10 modules.WebUsbProvider implements the SerialProvider interface using the WebUSB API. It is used as a polyfill for the native Web Serial API in scenarios where Web Serial is unavailable or unsupported, such as:
It supports CDC ACM (Class 0x02), common USB-UART bridges like CP210x and CH340 (Vendor-specific), and generic raw bulk-transfer devices.
Requirements: Requires a Chromium-based browser, HTTPS or localhost. Not supported in Firefox or Safari.
npm remove webserial-core
npm install webserial-core@latestWebUsbProvider implements SerialProvider using the WebUSB API. It is used as a polyfill for the native Web Serial API in scenarios where Web Serial is unavailable or unsupported, such as:
Browser Support: Requires a Chromium-based browser with WebUSB enabled. It is not available in Firefox or Safari. Connection requires HTTPS or localhost.
createWebSocketProvider factory function returns a SerialProvider that relays serial I/O to a Node.js bridge server over a WebSocket connection. This is useful for accessing serial ports on remote machines (e.g., Raspberry Pi), building web UIs for devices behind firewalls, or testing serial code where the Web Serial API is unavailable.import { createWebSocketProvider } from "webserial-core";
// Create a provider pointing to the bridge server
const provider = createWebSocketProvider("ws://127.0.0.1:8080/?token=TOKEN");webserial-core provides browser-based demos that run as static HTML pages using the UMD bundle, requiring no installation or build step. These demos require Chrome 89+ or Edge 89+ as they rely on browser-exclusive APIs. Safari and Firefox are not supported.
Available demos include: