Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'prevent-element-src-loading' — 'onerror', 'onload', 'link' #276

Closed
3 tasks
slavaleleka opened this issue Jan 9, 2023 · 0 comments
Closed
3 tasks

Comments

@slavaleleka
Copy link
Contributor

slavaleleka commented Jan 9, 2023

Original issue: #264

  • Fix issue with onerror (if I'm not wrong, it doesn't work correctly)
  • Add ability to return onload function
  • Add ability to prevent link

First, if I understand correctly, currently if there is onerror event then noopFunc is returned:

return Reflect.apply(target, thisArg, [eventName, noopFunc]);

What in case if there will be onload event?
Something like:

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js" onerror="showPopup();" onload="loadContent()"></script>

<script>
function showPopup() {
  alert('adblock');
}

function loadContent() {
 alert('content loaded');
}
</script>

Test website - https://jsfiddle.net/sL62htaz/
Will be onload executed or not?
If not, maybe it will be a good idea to check if onload is a function and then return it.


Second - at the moment we can prevent script, img and iframe, but lately I noticed that one of the websites is using link.
Something like:

<script>
(() => {
  const createScript = document.createElement("link");
  createScript.href = "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js";
  createScript.rel = "preload";
  createScript.as = "script";

  createScript.onload = () => {
    let video = '<iframe width="560" height="315" src="https://www.youtube.com/embed/Fy2rtb95QhY" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>';
    let createDiv = document.createElement("div");
    document.body.appendChild(createDiv);
    createDiv.innerHTML = video;
  };
  createScript.onerror = () => {
    alert("adblock");
  };
  document.body.appendChild(createScript);
})();
</script>

Test page - https://jsfiddle.net/e2un8pav/

Maybe we could also add link to possible values.

@slavaleleka slavaleleka changed the title Fix 'prevent-element-src-loading' — 'onerror' Fix 'prevent-element-src-loading' — 'onerror', 'onload', 'link' Jan 9, 2023
@slavaleleka slavaleleka added the bug Something isn't working label Mar 22, 2023
adguard pushed a commit that referenced this issue May 16, 2023
…nk'. #276

Squashed commit of the following:

commit 0328992
Merge: 5b79867 b3a7f6c
Author: Adam Wróblewski <adam@adguard.com>
Date:   Tue May 16 18:03:44 2023 +0200

    Merge branch 'master' into fix/AG-18720

commit 5b79867
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Fri May 12 11:53:23 2023 +0300

    escape slash

commit 4c8644b
Merge: 65cc633 b96e797
Author: Adam Wróblewski <adam@adguard.com>
Date:   Thu May 11 19:16:28 2023 +0200

    Merge branch 'master' into fix/AG-18720

commit 65cc633
Author: Adam Wróblewski <adam@adguard.com>
Date:   Thu May 11 17:02:13 2023 +0200

    Update changelog

commit 3e9f850
Author: Adam Wróblewski <adam@adguard.com>
Date:   Wed May 10 19:54:50 2023 +0200

    Improve prevent-element-src-loading
    Add ability to prevent link tag
    Add ability to prevent inline onerror
piquark6046 added a commit to List-KR/List-KR that referenced this issue Aug 16, 2023
If DNS filter is enabled in AdGuard for Android DNS module, the anti-adblock script will be activated.
AdguardTeam/Scriptlets#276
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants