declarativeNetRequest.testMatchOutcome

Checks if any of the extension's declarativeNetRequest rules would match a hypothetical request. Only available while testing, as this is intended to be used during extension development. See Testing for details on how testing is enabled in each browser.

Syntax

js
let result = await browser.declarativeNetRequest.testMatchOutcome(
    request,                // object
    options                 // optional object
);

Parameters

request

The details of the request to test.

initiator Optional

A string. The initiator URL (if any) for the hypothetical request.

method Optional

A string. The standard (lower case) HTTP method of the hypothetical request. Defaults to "get" for HTTP requests and is ignored for non-HTTP requests.

tabId Optional

A number. The ID of the tab the hypothetical request takes place in. Does not need to correspond to a real tab ID. Default is -1, meaning that the request isn't related to a tab.

type

declarativeNetRequest.ResourceType. The resource type of the hypothetical request.

url

A string. The URL of the hypothetical request.

options Optional

Details of options for the request.

includeOtherExtensions Optional

A boolean. Whether matching rules from other extensions are included in matchedRules. When rules from other extensions match, the resulting matchedRule has an extensionId property. Defaults to false.

Return value

A Promise that fulfills with an object with these properties:

matchedRules

declarativeNetRequest.MatchedRule. Details of the rules (if any) that match the hypothetical request.

If no rules match, the matchedRules array is empty. If the request fails, the promise is rejected with an error message.

Examples

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
testMatchOutcome
Chrome – Full support
Chrome 103 (Release date: 2022-06-21)
footnote Full support
Edge – Full support
Edge 103 (Release date: 2022-06-23)
footnote Full support
Firefox – Full support
Firefox 113 (Release date: 2023-05-09)
footnote Full support
Opera – Full support
Opera 89 (Release date: 2022-07-07)
footnote Full support
Safari – No support
Safari
footnote No support
Firefox for Android – Full support
Firefox for Android 113 (Release date: 2023-05-09)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
options
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 113 (Release date: 2023-05-09)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Firefox for Android – Full support
Firefox for Android 113 (Release date: 2023-05-09)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
options.includeOtherExtensions
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 113 (Release date: 2023-05-09)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Firefox for Android – Full support
Firefox for Android 113 (Release date: 2023-05-09)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support