← Web Bluetooth: Make BluetoothRemoteGATTServer an EventTarget

v157 · enabled by default · inherited method

BluetoothRemoteGATTServer.addEventListener()

Registers a listener for events of a given type on a BluetoothRemoteGATTServer. The method is inherited unchanged from EventTarget. It became available on the server when Chromium CL 8363084 made the interface inherit from EventTarget, as specified by Web Bluetooth PR #672. See the overview shipping note for which Chrome release contains it.

syntax

server.addEventListener(type, callback)
server.addEventListener(type, callback, options)
server.addEventListener(type, callback, useCapture)

Declared in the DOM Standard as:

undefined addEventListener(DOMString type, EventListener? callback, optional (AddEventListenerOptions or boolean) options = {});
Source: DOM §2.7 EventTarget IDL (verbatim); receiver per Web Bluetooth PR #672 IDL.

parameters

addEventListener() takes three arguments. The third can be an options dictionary or a boolean:

ParameterTypeMeaning
typeDOMStringThe event type to listen for. The spec defines one type for this target: "maxwritewithoutresponsesizechanged", which ships as a separate feature. Any other string is accepted and only matches events you dispatch yourself.
callbackEventListener?A function, or an object with a handleEvent(event) method. null is accepted and makes the call do nothing.
options.captureboolean, default falsePart of the listener’s identity. The server has no parent, so there is no capture or bubble path and capture listeners run in the at-target phase. Passing a boolean instead of a dictionary sets only capture.
options.onceboolean, default falseRemove the listener automatically after its first invocation.
options.passiveboolean, no defaultIf true, a call to preventDefault() in the listener is ignored.
options.signalAbortSignalWhen the signal aborts, the listener is removed. If it is already aborted, the listener is not added.
Source: DOM AddEventListenerOptions; DOM “add an event listener”; PR #672 event definition.

return value

addEventListener() returns undefined. The effect is that an entry is added to the server’s event listener list. If an entry with the same type, callback and capture is already registered, the call does nothing, so attaching the same function twice does not make it run twice.

Source: DOM “add an event listener” algorithm.

exceptions

Source: DOM EventTarget IDL; Web IDL; DOM dispatch (“report the exception”).

context

Available on any BluetoothRemoteGATTServer in a secure-context Window, whether or not the server is connected. You get the receiver from device.gatt, after requestDevice() (user gesture and chooser) or getDevices(). The gatt getter returns null in the spec unless the origin may use GATT on that device. The document must be allowed the "bluetooth" Permissions Policy feature. No extra permission is needed to add a listener.

Source: PR #672 IDL ([Exposed=Window, SecureContext]); Web Bluetooth gatt getter.

lifecycle

Source: Web Bluetooth §Bluetooth tree; DOM dispatch; CL 8363084.

examples

const device = await navigator.bluetooth.requestDevice({
  filters: [{ services: ["heart_rate"] }],
});
const server = device.gatt;

if (EventTarget.prototype.isPrototypeOf(BluetoothRemoteGATTServer.prototype)) {
  const controller = new AbortController();

  // The connection-level event designed for this target (separate feature).
  server.addEventListener("maxwritewithoutresponsesizechanged", () => {
    console.log("max write size:", server.maxWriteWithoutResponseSize);
  }, { signal: controller.signal });

  // Disconnects are still fired at the device: stop listening there.
  device.addEventListener("gattserverdisconnected", () => controller.abort(), { once: true });
}

await server.connect();
Source: written for this page against the DOM addEventListener() and PR #672 IDL; not executed against real hardware.

browser compatibility

BrowserOn BluetoothRemoteGATTServerEventTarget.addEventListener (BCD)
Chrome / Chrome AndroidListed for 157 (interim, ChromeStatus); code merged after the M159 branch point, so the first release is unknown1 (options object 49)
EdgeUnknown (not separately reported)12
FirefoxNo (no Web Bluetooth)1
SafariNo (no Web Bluetooth)1

BCD has no key for this inherited member on BluetoothRemoteGATTServer. The receiver column is interim data from ChromeStatus. The method column is from BCD api/EventTarget.json, and interface support is in BCD api/BluetoothRemoteGATTServer.json (both fetched 2026-11-15).

security and privacy

Adding a listener gives no access to device data and does not connect to the device or keep it connected. Any UA-fired event the listener receives is one the page could already observe through the server’s attributes. Web Bluetooth’s chooser, secure-context requirement, service allowlist, blocklist and Permissions Policy are unchanged.

Source: ChromeStatus API record (security risks).

see also