← Web Bluetooth: Make BluetoothRemoteGATTServer an EventTarget

v157 · enabled by default · inherited method

BluetoothRemoteGATTServer.dispatchEvent()

Synchronously dispatches an Event you created to a BluetoothRemoteGATTServer and runs the server’s matching listeners. The method is inherited unchanged from EventTarget. It became available on the server through Chromium CL 8363084 and Web Bluetooth PR #672. See the overview shipping note for which Chrome release contains it.

syntax

const notCanceled = server.dispatchEvent(event)

Declared in the DOM Standard as:

boolean dispatchEvent(Event event);
Source: DOM §2.7 EventTarget IDL (verbatim); receiver per Web Bluetooth PR #672 IDL.

parameters

dispatchEvent() takes one argument:

ParameterTypeMeaning
eventEventAn initialized event object that is not currently being dispatched, for example new Event("app:sync") or new CustomEvent("app:sync", { detail }). bubbles and composed have no effect here because the server has no parent. cancelable controls whether preventDefault() can change the return value.
Source: DOM dispatchEvent() steps; DOM “get the parent”.

return value

A boolean: false if event is cancelable and a listener called preventDefault() (ignored for passive listeners), otherwise true. During dispatch, event.target and event.currentTarget are the server and event.eventPhase is AT_TARGET (2). The DOM sets event.isTrusted to false for every event passed to dispatchEvent().

Source: DOM dispatchEvent(); DOM dispatch algorithm.

exceptions

Source: DOM dispatchEvent() step 1; DOM dispatch (report the exception); Web IDL.

context

Callable on any BluetoothRemoteGATTServer in a secure-context Window, connected or not. You get the receiver from device.gatt. Dispatching sends nothing to the Bluetooth device: it only runs JavaScript listeners in this page.

Source: PR #672 IDL; Web Bluetooth gatt getter.

lifecycle

Source: DOM dispatch; Web Bluetooth §Bluetooth tree; PR #672 §Responding to MTU changes.

examples

const server = device.gatt;

server.addEventListener("app:handshake", (event) => {
  console.log(event.target === server); // true
  console.log(event.isTrusted);         // false: script-dispatched
  if (!event.detail.ok) event.preventDefault();
});

device.addEventListener("app:handshake", () => {
  console.log("never runs: the server has no parent");
});

await server.connect();
const accepted = server.dispatchEvent(
  new CustomEvent("app:handshake", { cancelable: true, bubbles: true, detail: { ok: true } }),
);
console.log(accepted); // true
Source: written for this page against the DOM dispatchEvent() and Bluetooth tree definitions; not executed against real hardware.

browser compatibility

BrowserOn BluetoothRemoteGATTServerEventTarget.dispatchEvent (BCD)
Chrome / Chrome AndroidListed for 157 (interim, ChromeStatus); code merged after the M159 branch point, so the first release is unknown4
EdgeUnknown (not separately reported)12
FirefoxNo (no Web Bluetooth)2
SafariNo (no Web Bluetooth)3.1

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

security and privacy

Script-dispatched events always have isTrusted set to false, so code can tell them apart from events fired by the browser. Third-party script running in the same page can dispatch fake events on a server it can reach, so don’t treat event data as authoritative: read authoritative state from the server’s attributes. Dispatching an event sends no Bluetooth traffic.

Source: DOM dispatchEvent() (isTrusted false); ChromeStatus API record (security risks).

see also