I have a script that replaces the HTML of a webpage if a certain query string is present. The script needs to be loaded AFTER the HTML, but must be run and update the HTML BEFORE the page finishes loading, in order for my external script to detect the content of the page. Is there a way to achieve this?
I made this timeline diagram to show when the events should happen.
+--------------------------------+
| | |
E |=• Page begins loading |
v | | |
e |=====• Script runs and |
n | | website content changes |
t | | |
|=========• Page is loaded |
| | |
+--------------------------------+
^ ^ ^ Time
1 2 3