Getting the web element for the blocked ad

Various discussions related to Adblock Plus development
Post Reply
ankar

Getting the web element for the blocked ad

Post by ankar »

Hi,

I am working on a project where I need to identify the ads in a webpage and study them. I want to use ABP for effectively identifying the ads. But I noticed that ABP simply creates the CSS and passes it on to the browser.

From the source code:
In elemHide.js, apply() function:
Utils.styleService.loadAndRegisterSheet(styleURL, Ci.nsIStyleSheetService.USER_SHEET);

So I am not able to get a handle on the web element containing the advertisement.

Is there a way I can get a handle/reference to the web element for the ad itself? Any help will be appreciated.

Thanks.
lewisje
Posts: 2743
Joined: Mon Jun 14, 2010 12:07 pm

Re: Getting the web element for the blocked ad

Post by lewisje »

I thought that ABP for Firefox was able to show which elements were hidden, in the "Show Blockable Items" view; however, for content that is blocked (via nsIContentPolicy, not hidden via nsIStyleSheetService), it's harder to see what HTML elements contained the blocked content.

By the way, it is possible for content to be blocked while its containing element is also hidden, but one does not imply the other.
There's a buzzin' in my brain I really can't explain; I think about it before they make me go to bed.
ankar

Re: Getting the web element for the blocked ad

Post by ankar »

Thanks lewisje for the response.

So I was wondering if both content policy and element hiding are two separate things towards blocking the ad content. Also I think you suggested that I should backtrack from the browser side to find out what web elements are getting blocked because the browser shows the blockable elements?

Kindly clarify.

Thanks!
lewisje
Posts: 2743
Joined: Mon Jun 14, 2010 12:07 pm

Re: Getting the web element for the blocked ad

Post by lewisje »

ankar wrote:I was wondering if both content policy and element hiding are two separate things towards blocking the ad content
Yes: nsIContentPolicy is used when ABP parses blocking filters, to keep URLs matching them (and not matching whitelist filters) from being loaded; nsIStyleSheetService is used when ABP parses hiding filters, building up a stylesheet in which the selector after each matching domain specifier (that is, after the first occurrence of ##) is added to a big list of selectors, for which the CSS rule {display:none!important} is specified, before injecting the big stylesheet into the document.

Blocking URL requests and hiding HTML elements are separate processes.
There's a buzzin' in my brain I really can't explain; I think about it before they make me go to bed.
ankar
Posts: 5
Joined: Thu Apr 02, 2015 10:39 am

Re: Getting the web element for the blocked ad

Post by ankar »

Thanks for the explanation. I am trying to understand if there is any mechanism apart from content policy checking and hiding elements that Ad Block Plus follows to block ads? Or does it follow only these two approaches?

Additionally, with Ad block plus for Chrome, does the approach remain the same or does it change?
lewisje
Posts: 2743
Joined: Mon Jun 14, 2010 12:07 pm

Re: Getting the web element for the blocked ad

Post by lewisje »

The major difference between the Chrome and Firefox versions is that it's called the "webRequest API" in Chrome and it's less granular than nsIContentPolicy.
There's a buzzin' in my brain I really can't explain; I think about it before they make me go to bed.
Post Reply