dom module

class ContentEventObserverService(windowGlobal, sendAsyncMessage)

Provides the frame script backend for the WebElementEventTarget().

This service receives requests for new DOM events to listen for and to cease listening for, and despatches IPC messages to the browser when they fire.

  • windowGlobal (WindowProxy()) – Window.

  • sendAsyncMessage (nsIMessageSender.sendAsyncMessage()) – Function for sending an async message to the parent browser.


Observe a new DOM event.

When the DOM event of type fires, a message is passed to the parent browser’s event observer.

If event type is already being observed, only a single message is sent. E.g. multiple registration for events will only ever emit a maximum of one message.

  • type (string()) – DOM event to listen for.


Ceases observing all previously registered DOM events.


Ceases observing a DOM event.

  • type (string()) – DOM event to stop listening for.

class WebElementEventTarget(messageManagerFn)

The EventTarget for web elements can be used to observe DOM events in the content document.

A caveat of the current implementation is that it is only possible to listen for top-level window global events.

It needs to be backed by a ContentEventObserverService() in a content frame script.


let observer = new WebElementEventTarget(messageManager);
await new Promise(resolve => {
  observer.addEventListener("visibilitychange", resolve, {once: true});
  • messageManagerFn (function()) – Message manager to the current browser.

WebElementEventTarget.addEventListener(type, listener, once)

Register an event handler of a specific event type from the content frame.

  • type (string()) – Event type to listen for.

  • listener (EventListener()) – Object which receives a notification (a BareEvent) when an event of the specified type occurs. This must be an object implementing the EventListener interface, or a JavaScript function.

  • once (boolean()) – Indicates that the listener should be invoked at most once after being added. If true, the listener would automatically be removed when invoked.

WebElementEventTarget.removeEventListener(type, listener)

Removes an event listener.

  • type (string()) – Type of event to cease listening for.

  • listener (EventListener()) – Event handler to remove from the event target.