events API

The chrome.events namespace contains common types used by APIs dispatching events to notify you when something interesting happens.

Types

Event

An object which allows the addition and removal of listeners for a Chrome event.

object

  • addListener(callback) Registers an event listener callback to an event.

  • addRules(eventName, webViewInstanceId, rules, [callback]) Registers rules to handle events.

  • getRules(eventName, webViewInstanceId, [ruleIdentifiers], callback) Returns currently registered rules.

  • hasListener(callback)

  • hasListeners()

  • removeListener(callback) Deregisters an event listener callback from an event.

  • removeRules(eventName, webViewInstanceId, [ruleIdentifiers], [callback]) Unregisters currently registered rules.

Rule

Description of a declarative rule for handling events.

object

actions

(array of any)

List of actions that are triggered if one of the condtions is fulfilled.

conditions

(array of any)

List of conditions that can trigger the actions.

[id]

(string, optional)

Optional identifier that allows referencing this rule.

[priority]

(integer, optional)

Optional priority of this rule. Defaults to 100.

[tags]

(array of string, optional)

Tags can be used to annotate rules and perform operations on sets of rules.

UrlFilter

Filters URLs for various criteria. See event filtering. All criteria are case sensitive.

object

[hostContains]

(string, optional)

Matches if the host name of the URL contains a specified string. To test whether a host name component has a prefix ‘foo’, use hostContains: ‘.foo’. This matches ‘www.foobar.com’ and ‘foo.com’, because an implicit dot is added at the beginning of the host name. Similarly, hostContains can be used to match against component suffix (‘foo.’) and to exactly match against components (‘.foo.’). Suffix- and exact-matching for the last components need to be done separately using hostSuffix, because no implicit dot is added at the end of the host name.

[hostEquals]

(string, optional)

Matches if the host name of the URL is equal to a specified string.

[hostPrefix]

(string, optional)

Matches if the host name of the URL starts with a specified string.

[hostSuffix]

(string, optional)

Matches if the host name of the URL ends with a specified string.

[originAndPathMatches]

(string, optional)

Matches if the URL without query segment and fragment identifier matches a specified regular expression. Port numbers are stripped from the URL if they match the default port number. The regular expressions use the RE2 syntax.

[pathContains]

(string, optional)

Matches if the path segment of the URL contains a specified string.

[pathEquals]

(string, optional)

Matches if the path segment of the URL is equal to a specified string.

[pathPrefix]

(string, optional)

Matches if the path segment of the URL starts with a specified string.

[pathSuffix]

(string, optional)

Matches if the path segment of the URL ends with a specified string.

[ports]

(array of integer or array of integer, optional)

Matches if the port of the URL is contained in any of the specified port lists. For example [80, 443, [1000, 1200]] matches all requests on port 80, 443 and in the range 1000-1200.

[queryContains]

(string, optional)

Matches if the query segment of the URL contains a specified string.

[queryEquals]

(string, optional)

Matches if the query segment of the URL is equal to a specified string.

[queryPrefix]

(string, optional)

Matches if the query segment of the URL starts with a specified string.

[querySuffix]

(string, optional)

Matches if the query segment of the URL ends with a specified string.

[schemes]

(array of string, optional)

Matches if the scheme of the URL is equal to any of the schemes specified in the array.

[urlContains]

(string, optional)

Matches if the URL (without fragment identifier) contains a specified string. Port numbers are stripped from the URL if they match the default port number.

[urlEquals]

(string, optional)

Matches if the URL (without fragment identifier) is equal to a specified string. Port numbers are stripped from the URL if they match the default port number.

[urlMatches]

(string, optional)

Matches if the URL (without fragment identifier) matches a specified regular expression. Port numbers are stripped from the URL if they match the default port number. The regular expressions use the RE2 syntax.

[urlPrefix]

(string, optional)

Matches if the URL (without fragment identifier) starts with a specified string. Port numbers are stripped from the URL if they match the default port number.

[urlSuffix]

(string, optional)

Matches if the URL (without fragment identifier) ends with a specified string. Port numbers are stripped from the URL if they match the default port number.