Module: index

Members

(static) contentTypes :Object

Content types for request blocking and allowing (allowlisting).

There are two kinds of content types: resource types, and special (non-resource) types.

Resource types include web resources like scripts, images, and so on.

Special types include filter options for popup blocking and CSP header injection as well as flags for allowing documents.

By default a filter matches any resource type, but if a filter has an explicit resource type, special option, or allowing flag, like $script, $popup, or $elemhide, then it matches only the given type, option, or flag.

Type:
  • Object
Source:

(static) filterEngine :module:filterEngine~FilterEngine

The filterEngine object maintains filters for request blocking, element hiding, and snippets.

Type:
Source:
Example
let {contentTypes, filterEngine} = require("adblockpluscore");

await filterEngine.initialize(
  [
    "/annoying-ad^$image",
    "||example.com/social-widget.html^"
  ]
);

let resource = {
  url: "https://ad-server.example.net/annoying-ad.png",
  documentURL: "https://news.example.com/world.html"
};

let filter = filterEngine.match(resource.url, contentTypes.IMAGE,
                                new URL(resource.documentURL).hostname);
console.log(filter); // prints "/annoying-ad^$image"

Methods

(static) parseURL(url) → {module:url~URLInfo}

Parses a URL to extract the protocol and the hostname.

This is a lightweight alternative to the native URL object intended for use primarily within Adblock Plus. Unlike the URL object, the parseURL() function is not robust and will give incorrect results for invalid URLs. Use this function with valid, normalized, properly encoded (IDNA, etc.) URLs only.

Parameters:
Name Type Description
url string

The URL.

Source:
Returns:

Information about the URL.

Type
module:url~URLInfo