Frage

I want to implement an extension for browsers that blocks third party pop up ads, something on the lines of the Ad Blocker. But I don't know where to start. Can someone point me towards some references that I can use to learn more about filtering web content? Thanks in advance.

War es hilfreich?

Lösung 2

I hate to just shove you to links you have probably found but everything you need really is on here:

http://developer.chrome.com/extensions/index.html

If you take the time to read it you'll understand how the extension is built and lives in the browser. If you read long enough you'll find this section:

http://developer.chrome.com/extensions/content_scripts.html

Which details how you can inject javascript into a tab and run it with the context of the page vs. the context of your plugin.

The resources are fairly detailed, you just have to read them.


To follow up with your comment, no. Every browser environment is architected differently and you'll likely have to take a different approach to the same problem, even if the goal is the same.

The way I see it, there's 2 ways of doing this (at a high level). Stop the transmission from even happening, or retroactively remove the elements from the page after it's loaded.

If you stop the transmission, it's better because it should prevent a lot of drive-by exploits as the bytes never make it to the computer, or at least to the page.

As duskwuff explained, chrome has an API that lets you intercept requests and make that decision at that time. IE is going to have a totally different api than chrome, and firefox is different from both.

Taking a retro-active approach you could possibly build some javascript that's x-platform that runs against the page and removes ads. This will work "cross-browser" if you can find a unique method for injecting/executing this script in a tab on all browsers, but the implementation of that portion will be unique to the platform.

Different browsers even use different languages.

Chrome uses JS/HTML5 for most extensions, you can use native DLLs apparantly but you're treated with higher scrutiny when you submit your extension to the store because the binary needs to be vetted that it wont expose problems for the browser because the html/js versions live inside the sandbox and can be properly isolated.

Firefox has changed quite a bit in the last while, I haven't kept up to date with thier changes, but it's a totally different ballgame. Thier extension framework at one point had been matured enough to build small standalone apps iirc, but i may be wrong.

IE is mainly COM extensions, it may have changed a bit in the last while but you'll likely be making .NET or C++ .dlls that interop with a COM interface for the browser.

So as you can see it's greatly different for each browser, then there's all the outliers (Safari / Opera / etc...)

Let's not forget a lot of these browsers also are cross-platform and depending on how you attack the problem you may have to take that into account.


It's also worth noting: Chrome is an asynchronous model, each tab / plugin lives "isolated" from each other, and communicate using asynchronous messaging basically. This makes the general approach for working with the browser fundamentally different than other browsers because you need to work inside callback methods a lot.

Andere Tipps

For Google Chrome, the basis of ad blocking is the chrome.webRequest API, which will give an extension information on ongoing web requests, and will allow it to intercept or modify an in-flight request.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top