Search code examples
javascriptgoogle-chrome-extensionfirefox-addon-webextensionsbrowser-extension

Is there a way to run a content script after the page is loaded but before scripts are executed?


I'm writing a browser extension to intercept all the script tags on the page when it's loaded, but before they execute. To be clear, I'm not looking to block the scripts entirely; I just want to intercept and analyze/modify them before they're run.

Is there a way to do this?

I'm aware of onbeforescriptexecute for Firefox and its polyfill for Chrome, but I'm hoping for something more "official" and cross-browser...


Solution

  • As answered by CertainPerformance in the comments, you can use a MutationObserver to observe changes to the DOM as shown here: https://stackoverflow.com/a/59518023