简体   繁体   中英

Is it possible to stop a javascript with Firebug without using breakpoints?

Is it possible with Firebug to stop a javascript with a press of a button or a keyboard shortcut instead of stopping it by setting a breakpoint?

Why would I like to do this? We have a very dynamic website with lots of animations. It would be a great help if I could just stop the scripts at the moment the animation is doing something I want to inspect. That would be a lot faster than fiddling with the breakpoints.

This is how I did it, from the web console (not the scratchpad), run:

window.addEventListener("keydown", function() {debugger;})

Then go back to the debugger tab. When you focus the document and press a key, the browser will pause JS.

There is a pause button in Firebug. Clicking on that is what you are looking for.

Firebug has different ways to stop the script execution without setting breakpoints at specific lines. These options are called Break On features .

In your case I see two relevant options:

  1. Break the JavaScript on the next executed line
    The Script panel has a Break On Next button ( * Break On Next *按钮 ), which allows you to stop the script execution at the next executed JavaScript statement. This feature can also be enabled via the keyboard shortcut Ctrl + Alt + B .

    So, just hit the keyboard shortcut once the animation is at the point when you want to inspect it.

  2. Break on HTML mutation
    The HTML panel has a Break On Mutate button ( * Break On Mutate *按钮 ), which allows you to stop the script execution at the next HTML mutation.
    There are also more fine grained options to stop at the mutation of a specific element, which are available within the context menu of the elements. Those options are:

    • Break On Attribute Change : Stops the script execution when an attribute of the element is added, changed or removed.
    • Break On Child Addition or Removal : Stops the script execution when a child node is added or removed.
    • Break On Element Removal : Stops the script execution when the element itself is removed.

    In your case Break On Attribute Change may be the right choice in case the animation changes the CSS within the style attribute of the element.

If you know where it's doing something you want to inspect, then what is wrong with breakpoints? Also, you can use the debugger keyword in the code, or you can inject console.log/debug/warn/info statements in your code. (You can stub out the console object for those environments that don't have one).

如果您使用Web开发人员插件,则可以禁用所有java脚本在页面上运行,然后根据需要使用firebug。

From what you describe, I'm guessing javascript console logging from your code might help you best. Check out http://getfirebug.com/wiki/index.php/Console_API .

depending on the animation library you're using, there might be a 'stop all animations' method - jQuery's .stop() , for instance. how are you handling the animations?

The best way to fix this is go to the HTML drop down which is there next the HTML tab in firebug. Deselect "highlight changes" and "scroll changes to view" and that should allow you to inspect the html and css code that is being executed. I hope you guys wanted to do this.

If the web site is continually reloading content from your server, you can switch to the Net pane. The context menu there has a "Break on XHR" entry which, when checked, will stop your script whenever it tries to get new content.

The easiest way is to install the firefox extension "PrefBar". There you can add a checkbox "JavaScript". If you deactivate it, javascript stopped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM