Opened on 02/25/2016 at 08:05:36 AM

Closed on 03/18/2016 at 07:39:08 PM

Last modified on 04/19/2016 at 11:58:23 PM

#3699 closed change (fixed)

Patch DOM API in order to prevent disabling the injected stylesheet

Reported by: mapx Assignee: sebastian
Priority: P3 Milestone: Adblock-Plus-1.12-for-Chrome-Opera-Safari
Module: Platform Keywords:
Cc: kzar, greiner, sebastian Blocked By:
Blocking: Platform: Chrome
Ready: yes Confidential: no
Tester: Ross Verified working: yes
Review URL(s):

Description (last modified by sebastian)


Some websites (e.g. currently circumvent element hiding by messing (usually disabling) the style sheet we inject in order to hide ads.

We already detect when the <style> is removed from the DOM, in which case we reinject the rules in the last stylesheet by the page itself (#1677). However, MutationObserver or other DOM APIs don't allow for detecting when the stylesheet gets disabled.

But with some effort it's possible to monkey-patch the DOM API in order to intercept code messing with our style sheet.

What to change

Patch the DOM API, ignoring calls that would disable stylesheets or remove their rules.

Attachments (0)

Change History (14)

comment:1 Changed on 02/25/2016 at 08:06:39 AM by mapx

  • Description modified (diff)

comment:2 Changed on 02/25/2016 at 12:49:10 PM by greiner

I'm currently looking into it. There's definitely a circumvention script by running on the page that tries to mess with us.

However, blocking tblwd_b.js seems so to work as a temporary solution.

comment:3 Changed on 02/25/2016 at 01:15:22 PM by mapx

no change adding


You have to wait other 10 seconds and the second (bigger) banner will appear.

comment:4 follow-up: Changed on 03/17/2016 at 04:01:38 PM by mapx

"the site is removing ABP's/AdBlock's injected CSS rules, and also disable their injected stylesheets though the StyleSheet.disabled property."


comment:5 in reply to: ↑ 4 Changed on 03/17/2016 at 07:46:43 PM by sebastian

  • Description modified (diff)
  • Owner set to sebastian
  • Priority changed from Unknown to P3
  • Ready set
  • Summary changed from css rules / style disabled in chrome ? to Patch DOM API in order to prevent disabling the injected stylesheet
  • Type changed from defect to change

Replying to mapx:

I can see (at the top of the page, after the shadow section) using inspect:

style {                 user agent stylesheet

    display: none;

Does this mean can't be injected user css rules / stylesheets ?

No, that just means that <style> themselves are generally not visible.

Replying to mapx:

"the site is removing ABP's/AdBlock's injected CSS rules, and also disable their injected stylesheets though the StyleSheet.disabled property."

I can confirm that they disable it. It doesn't seem that they remove it.

Anyway, I think I found a reliable way to tackle that kind of circumvention, it's quite ugly though, see the updated issue description. But given that the practice of messing with our stylesheet becomes increasingly popular, I guess we have to do that.

comment:6 Changed on 03/17/2016 at 07:47:45 PM by sebastian

  • Review URL(s) modified (diff)
  • Status changed from new to reviewing

comment:7 Changed on 03/18/2016 at 05:29:19 PM by sebastian

  • Description modified (diff)

comment:8 Changed on 03/18/2016 at 07:37:09 PM by abpbot

A commit referencing this issue has landed:

comment:9 Changed on 03/18/2016 at 07:39:08 PM by sebastian

  • Milestone set to Adblock-Plus-for-Chrome-Opera-Safari-next
  • Resolution set to fixed
  • Status changed from reviewing to closed

comment:10 Changed on 03/18/2016 at 08:23:28 PM by mapx

I tested this page:

with 1.11 (or before the page is responsive, normal CPU.

with the last, the page becomes unresponsive, high CPU.

Last edited on 03/18/2016 at 08:24:19 PM by mapx

comment:11 Changed on 03/18/2016 at 11:04:21 PM by sebastian

If I remove the code that prevents to "disable" our stylesheet that page load normally, but well the stylesheet can be disabled again. Interestingly, even if I fake HTMLStyleElement.disabled and CSSStyleSheet.disabled in a way that it can still be set to true and return that value as well, but without having any effect, the page still gets CPU usage up to 100%. So in other words, there is nothing we can do to prevent that, while preventing websites from disabling our stylesheet at the same time.

comment:12 Changed on 03/18/2016 at 11:24:13 PM by mapx

it's one of these scripts which does all this mess:*

comment:13 Changed on 03/19/2016 at 12:09:08 AM by mapx

anyway (it's only for testing, I don't visit the site)

these filters are working (no high CPU)[src^="data:image"][href^=""][class*="-universalsmall"]

comment:14 Changed on 04/19/2016 at 11:58:23 PM by Ross

  • Tester changed from Unknown to Ross
  • Verified working set

Element hiding no longer looks circumvented on

Chrome 32 / 44 / 48 / Windows 8
Chrome 44 / Ubuntu 14.04
Chrome 44 / OS X 10.11

Add Comment

Modify Ticket

Change Properties
as closed .
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from sebastian.
Note: See TracTickets for help on using tickets.