為了改善您的使用體驗,本網站正在進行維護,部分功能暫時無法使用。若本站的文件無法解決您的問題,想要向社群發問的話,請到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 發問,我們的社群成員將很快會回覆您的疑問。

搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

了解更多

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?

所有回覆 (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.

由 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