Question

Old Opera 12 had an easy option to build own ad-blocking extension: http://dev.opera.com/articles/view/extensions-api-urlfilter/

My question is: Is there a similar thing in google chrome extension format ? (also this should apply for new opera series)

(This is a question also about how various adblocks for chrome are made. I mean do these extensions actually block traffic before the browser sends request ? Is this capacity available in chrome extensions ?)

Was it helpful?

Solution

There are two APIs that can be used for blocking web content:

  1. The chrome.webRequest API.
  2. The chrome.declarativeWebRequest API.

The declarativeWebRequest is currently only available on the dev channel, but I expect that it will become available on the stable channel within a few releases. Although it's possible to block requests using the webRequest API, I recommend to use the declarative one, because it's more efficient, in two ways: it allows you to use event pages instead of background pages, and the filters are fully implemented in native code.

The format of the URL filters of the declarativeWebRequest API are very expressive, its format can be found at https://developer.chrome.com/extensions/events.html#type-UrlFilter.

The format of the URL filter in the declarativeWebRequest API follows the format of a match pattern (similar to Opera's url filter).

I've posted a simple example of both APIs at Block URL with a specific word somewhere in the subdomain. Don't forget to declare the right permissions in the manifest file. Either "declarativeWebRequest" or "webRequest", "webRequestBlocking". To block an URL using the webRequest API, you must also request permissions to access the URLs you want to block in the manifest file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top