demo · v130

SerialPort.connected probe

Click "request port" to pair a serial device (USB or RFCOMM Bluetooth). The probe reports whether the new connected attribute exists and tracks live connect / disconnect events so you can hot-unplug and watch the state flip.

requires Web Serial + a real device Web Serial is desktop-only and the dialogue requires a user gesture. RFCOMM port enumeration also requires chrome://flags/#enable-experimental-web-platform-features on some channels. The page feature-detects and shows the probe even without a port paired.
(no granted ports yet)

the code

const port = await navigator.serial.requestPort({
  allowedBluetoothServiceClassIds: ["00001101-0000-1000-8000-00805f9b34fb"],
});

// v130: synchronous boolean — true when the device is currently reachable.
console.log("connected:", port.connected);

// v130: connect/disconnect fire on SerialPort itself for RFCOMM
// (not just on navigator.serial), so each port instance reports its own state.
port.addEventListener("connect", () => console.log("re-connected"));
port.addEventListener("disconnect", () => console.log("disconnected"));

see also