addEventListener()

Adds a listener for a custom event type or a standard event type when the event is fired. This method adds a listener for custom event types in API version 25.0 or later; it adds a listener for standard event types in API version 30.0 or later.

For the list of standard events, see Methods for Console Events.

NameTypeDescription
eventTypestringCustom event type for which eventListener listens.
eventListenerfunctionJavaScript method called when an eventType is fired.
additionalParamsobjectOptional parameters accepted by this method. The supported properties on this object are tabId: The ID of the tab to listen for the specified event. This argument is only available in API version 30.0 or later.

This method is asynchronous, so it returns its response in an object in a callback method. The response object contains the following field:

NameTypeDescription
messagestringThe message which is sent with the fired event. If the response is from a custom keyboard shortcut, the message includes the following information on which the browser is focused, in this order:
  1. Object ID of the primary tab
  2. ID of the primary tab
  3. Object ID of the subtab
  4. ID of the subtab

This method is asynchronous, so it returns its response in an object in a callback method. The response object contains the following field:

NameTypeDescription
messagestringThe message which is sent with the fired event. If the response is from a console event, the message includes payload details as described in Methods for Console Events. If the response is from a custom keyboard shortcut, the message includes the following information on which the browser is focused, in this order:
  1. Object ID of the primary tab
  2. ID of the primary tab
  3. Object ID of the subtab
  4. ID of the subtab