← Web Bluetooth: Make BluetoothRemoteGATTServer an EventTarget
v157 · enabled by default · inherited method
BluetoothRemoteGATTServer.removeEventListener()
Unregisters a listener that was added to a BluetoothRemoteGATTServer with addEventListener(). 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
server.removeEventListener(type, callback)
server.removeEventListener(type, callback, options)
server.removeEventListener(type, callback, useCapture)
Declared in the DOM Standard as:
undefined removeEventListener(DOMString type, EventListener? callback, optional (EventListenerOptions or boolean) options = {});
Source: DOM §2.7 EventTarget IDL (verbatim); receiver per Web Bluetooth PR #672 IDL.
parameters
removeEventListener() finds the listener to remove by three values, which must all match the original registration:
| Parameter | Type | Meaning |
|---|---|---|
type | DOMString | The event type the listener was registered for, for example "maxwritewithoutresponsesizechanged". |
callback | EventListener? | The same function or object that was passed to addEventListener(). A new arrow function with the same body does not match. |
options.capture | boolean, default false | Must equal the capture value used when the listener was added. Only capture is part of the match; once, passive and signal are ignored here. A boolean argument is the same as { capture: bool }. |
return value
removeEventListener() returns undefined. If the server’s listener list has an entry with the same type, callback and capture, that entry is marked removed and dropped from the list. Otherwise nothing happens. Calling it for a listener that was never added, or was already removed, is a silent no-op.
exceptions
- The method does not throw for an unknown
type, an unregistered callback ornull. TypeErrorifcallbackis a non-object primitive (Web IDL conversion), or if called with athisthat is not anEventTarget.- On a browser without the inheritance change,
server.removeEventListenerisundefined, so calling it throwsTypeError: server.removeEventListener is not a function. Use the same feature check as foraddEventListener().
context
Available on any BluetoothRemoteGATTServer in a secure-context Window, connected or not. You get the receiver from device.gatt. No permission prompt or user gesture is involved.
lifecycle
- Removing a listener while the server is dispatching an event stops it from running for the rest of that dispatch, because it is marked as removed.
- A disconnect does not remove listeners. The server object persists for the life of the
BluetoothDevice, so remove listeners yourself when a feature of your app shuts down. - Aborting the
AbortSignalpassed asoptions.signaltoaddEventListener()has the same effect and does not need the original callback reference.
examples
const server = device.gatt;
function onSizeChange() {
console.log("max write size:", server.maxWriteWithoutResponseSize);
}
server.addEventListener("maxwritewithoutresponsesizechanged", onSizeChange);
// Later, when the transfer UI closes:
server.removeEventListener("maxwritewithoutresponsesizechanged", onSizeChange);
// This does NOT remove it, because the capture flag differs:
server.removeEventListener("maxwritewithoutresponsesizechanged", onSizeChange, true);
Source: written for this page against the DOM removeEventListener() and PR #672 IDL; not executed against real hardware.
browser compatibility
| Browser | On BluetoothRemoteGATTServer | EventTarget.removeEventListener (BCD) |
|---|---|---|
| Chrome / Chrome Android | Listed for 157 (interim, ChromeStatus); code merged after the M159 branch point, so the first release is unknown | 1 (options object 49) |
| Edge | Unknown (not separately reported) | 12 |
| Firefox | No (no Web Bluetooth) | 1 |
| Safari | No (no Web Bluetooth) | 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
Taking a listener off the list changes no device state, sends no Bluetooth traffic and needs no permission. It reveals nothing beyond the prototype-chain change described on the overview.
Source: ChromeStatus API record (security risks).