Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

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

@slavaleleka

Description

@slavaleleka

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.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions