Join the AMA (Ask Me Anything) with the Firefox leadership team to celebrate Firefox 20th anniversary and discuss Firefox’s future on Mozilla Connect. Mark your calendar on Thursday, November 14, 18:00 - 20:00 UTC!

This site will have limited functionality while we undergo maintenance to improve your experience. If an article doesn't solve your issue and you want to ask a question, we have our support community waiting to help you at @FirefoxSupport on Twitter and/r/firefox on Reddit.

Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

How do I set a breakpoint on the first line of the first script in a page?

more options

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?

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?

All Replies (5)

more options

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.

Modified by Wesley Branton

more options

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?

more options

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.

more options

Here is a website with some further information on setting a Javascript breakpoint. The steps can be done using Firebug:

more options

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