Back to Repository

Block All 3rd Party Scripts

1 upvotes
By Default Upload
Before page load (document_start)

Description

Blocks all 3rd party scripts from loading on all sites.

Match Pattern

<all_urls>

Script Code

(function () {
  const currentHost = location.hostname;
  const origAppendChild = Element.prototype.appendChild;
  Element.prototype.appendChild = function (el) {
    if (el.tagName === 'SCRIPT' && el.src) {
      try {
        const url = new URL(el.src);
        if (url.hostname !== currentHost) {
          console.warn('⛔ Blocked all 3rd-party script:', el.src);
          return el;
        }
      } catch (_) {}
    }
    return origAppendChild.call(this, el);
  };
})();
Install requires the InjectJS Chrome extension. Scripts run only on sites matching the pattern above. Review code before installing any community script.