Module: dnr/index

Methods

(static) createConverter(options) → {function}

Returns a callback bound to the given options.

Parameters:
Name Type Description
options ConverterOptions

in Mv3 Web extensions this would be chrome.declarativeNetRequest.isRegexSupported, so that it's possible to pass chrome.declarativeNetRequest directly as option.

Source:
Returns:
Type
function

(inner) asDNR(parsedFilter) → {Array.<Rule>|Error}

Convert a parsed filter to a DeclarativeNetRequest

To work properly this function must be bound to an object that has a method isRegexSupported that will return whether the RegExp passed as argument is valid or not for DNR. This is necessary as they have to be RE2 expection and this syntax isn't supported by native JavaScript. There is a (native) node module or the Chrome WebExtension API. createConverter will provide a default function that always return true.

Parameters:
Name Type Description
parsedFilter module:filters/index~ParsedFilter

The parsed filter object.

Source:
Returns:
Type
Array.<Rule> | Error

(inner) convert(text) → {Array.<Rule>|FilterParsingError}

Returns an array with DNR Rules if the text is network related, or an Error if no suitable rule can be created.

Parameters:
Name Type Description
text string

the filter text to convert or the generated error.

Source:
Returns:
Type
Array.<Rule> | FilterParsingError

Type Definitions

ConverterOptions

Type:
  • Object
Properties:
Name Type Description
isRegexSupported function

a sync/async method to check if a generic regular expression is compatible with the engine.

Source:

Rule

see https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/#type-Rule

Type:
  • Object
Properties:
Name Type Attributes Description
action object

see https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/#type-RuleAction

condition object

see https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/#type-RuleCondition

id number

a unique identifier for this rule

priority number <nullable>

optional priority of the filter

Source: