Is there a way to run Google Chrome script content after loading the DOM, but before any page scripts are executed?

I need to remove the script from the page before it is executed, because it interferes with my script ...

If I set run_at to document_start, I do not have access to the DOM because it is not loaded. But when it is loaded, the scripts on the page also execute ...

Is there a way to tell Chrome to run my content script before running any scripts from the page?

I understand that Javascript only runs when the code loads ... but maybe there is a way to disable this behavior when using the contents of the script?

+4
source share
2 answers

I think that it is much better for you to have a server solution that removes this file from the template in case you do not want it. Everything that is done in Javascript will be very inconvenient and inaccessible (if at all possible)

0
source

Just load the contents of the DOM for each script and set the order you want to execute:

<script> // First document.addEventListener ("DOMContentLoaded", function () {}, false) </script> <script> // Second document.addEventListener ("DOMContentLoaded", function () {}, false) </script> <script> // Third document.addEventListener ("DOMContentLoaded", function () {}, false) </script> ... 

Remember that for external scripts, the async method will probably not execute in that order.

+1
source

Source: https://habr.com/ru/post/1339236/


All Articles