Opened 5 months ago

Closed 5 months ago

Last modified 5 months ago

#7207 closed change (fixed)

Implement abort-on-property-write snippet

Reported by: hfiguiere Assignee: hfiguiere
Priority: P2 Milestone:
Module: Core Keywords: circumvention
Cc: mjethani, arthur Blocked By:
Blocking: Platform: Unknown / Cross platform
Ready: yes Confidential: no
Tester: Ross Verified working: yes
Review URL(s):

https://codereview.adblockplus.org/29979555/

Description (last modified by hfiguiere)

Background

Similarly to issue #6969

Some circumvention scripts depend on global properties on the window object. The execution of such scripts can be aborted by throwing an error when the property is written (set).

There is a technique in uBlock Origin called abort-on-property-write that does this.

What to change

Implement a snippet called abort-on-property-write that wraps a given property of the window object and throws an error if the property is written (set).

Hints for testers

Try this:

<!-- test.html -->
<div>
  Lorem ipsum dolor sit amet, consectetur
  adipiscing elit, sed do eiusmod tempor
  incididunt ut labore et dolore magna aliqua.
</div>
<script src="script.js"></script>
/* script.js */
setTimeout(() =>
{  
  if (!window.adsShowing)
  {
    window.adsShowing = true;
    let ad = document.createElement("div");
    ad.id = Math.random().toString(36).substring(2);
    ad.innerHTML = "<div><span>Check this!</span><span class='label'>Ad</span></div>";
    document.body.appendChild(ad);
  }
},
500);

When you load this page, it should show the "Check this!" ad. If you then add the filter localhost#$#abort-on-property-write adsShowing and reload the page, the ad should no longer be shown. Also there should be no error in the tab's console.

Change History (13)

comment:1 Changed 5 months ago by hfiguiere

  • Cc mjethani arthur added

comment:2 Changed 5 months ago by hfiguiere

  • Description modified (diff)

comment:3 Changed 5 months ago by sdixit

Let's get code review done so that we have a chance to release this before code freeze. Manish: Could you please help on this?

comment:4 Changed 5 months ago by mjethani

  • Owner set to hfiguiere
  • Priority changed from Unknown to P2
  • Ready set

comment:5 Changed 5 months ago by abpbot

A commit referencing this issue has landed:
Issue 7207 - Implement abort-on-property-write snippet

comment:6 Changed 5 months ago by hfiguiere

  • Resolution set to fixed
  • Review URL(s) modified (diff)
  • Status changed from new to closed

comment:7 Changed 5 months ago by abpbot

A commit referencing this issue has landed:
Issue 7207 - Implement abort-on-property-write snippet

comment:8 Changed 5 months ago by Ross

Working in the browser versions below. Will verify once able to test on minimum versions.

ABP 3.4.2.2231
Chrome 71.0.3578.98 / Windows 10
Firefox 64.0.2 / Windows 10

comment:9 Changed 5 months ago by Ross

  • Tester changed from Unknown to Ross
  • Verified working set

Implemented and working.

ABP 3.4.2.2231
Chrome 71.0.3578.98 / Windows 10 (Latest)
Chrome 49.0.2623.75 / Windows 10 (Min supported)
Firefox 64.0.2 / Windows 10 (Latest)
Firefox 51.0 / Windows 10 (Min supported)
Opera 57.0.3098.76 / Windows 10 (Latest)
Opera 36.0.2130.65 / Windows 10 (Min supported)

comment:10 Changed 5 months ago by mjethani

  • Sensitive unset

comment:11 Changed 5 months ago by Ross

Does not work in Edge. Should it? I will open a new ticket if so.

ABP 0.9.12.2237
Edge 44.17763.1.0 / EdgeHTML 18.17763 / Windows 10

comment:12 Changed 5 months ago by mjethani

Let's open a new ticket for Edge, in my opinion.

comment:13 Changed 5 months ago by hfiguiere

It should work in Edge, but the example might not as there are other timing consideration in place.

What you can try is, on the same page as in the test procedure, open the devtools and in the JS console try to do the following:

window.adsShowing = true

You should get an error.

Note: See TracTickets for help on using tickets.