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.

Arguments:
  • windowGlobal (WindowProxy) – Window.
  • sendAsyncMessage (nsIMessageSender.sendAsyncMessage) – Function for sending an async message to the parent browser.
ContentEventObserverService.add(type)

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.

Arguments:
  • type (string) – DOM event to listen for.
ContentEventObserverService.clear()

Ceases observing all previously registered DOM events.

ContentEventObserverService.remove(type)

Ceases observing a DOM event.

Arguments:
  • type (string) – DOM event to stop listening for.
class WebElementEventTarget(messageManager)

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.

Usage:

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

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

Arguments:
  • 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.

Arguments:
  • type (string) – Type of event to cease listening for.
  • listener (EventListener) – Event handler to remove from the event target.