How do I set a breakpoint on the first line of the first script in a page?
Hello, everyone.
My question is the following:
I am using an inspector/debugger from the Firefox Development Tools. (Triggered by F12)
What I need is to set a breakpoint on the first line of the first 'script' tag Firefox encounters when loading a page.
The thing is, I don't know even which line in the webpage code the scripts starts at, since it is a heavily dynamic page which changes every time you reload it.
Is it possible to achieve?
Alle antwurden (5)
If you are talking about adding a breakpoint to Javascript, you would need to use a Javascript code bookmarklet to scan the entire page and add break;
inside of the first script. Unfortunately, this wouldn't stop all of the scripts, as many web developers use multiple script blocks in HTML. Also, it probably wouldn't stop script files outside of the HTML code from loading. And it would also be a very taxing process for your code to look through an entire HTML page each time it loads.
If I may ask, for what purpose do you wish to make their modifications to the pages that you visit? There may be an addon that can achieve what you want.
Thanks.
Bewurke troch Wesley Branton op
Well... did you actually mean to add 'debugger();' to the code?
Generally, it seems a good idea to rewrite all 'script' tags in a page to include a breakpoint, but could you expand your answer a bit more: how do I make my script process a webpage ~before~ everything else starts to load?
My first thought is Greasemonkey, but I am not sure it can be forced to run in the exact moment when the page code has been downloaded, but has not yet been parsed.
I would also have to stop pipelining and multithreading, right?
As I investigate this further, I think that what you are trying to achieve may not be possible because it would need to be loaded before the webpage is rendered in the browser.
Here is a website with some further information on setting a Javascript breakpoint. The steps can be done using Firebug:
Lockywolf said
My first thought is Greasemonkey, but I am not sure it can be forced to run in the exact moment when the page code has been downloaded, but has not yet been parsed.
Probably not at that exact moment:
https://wiki.greasespot.net/Metadata_Block#.40run-at
https://wiki.greasespot.net/DOMContentLoaded
Here's an old thread on StackOverflow about doing it with Firebug, but so much can change in 7 years that it may be completely obsolete: http://stackoverflow.com/questions/1938397/telling-firebug-to-break-as-soon-as-any-javascript-is-executed