开发者

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

开发者 https://www.devze.com 2022-12-27 06:05 出处:网络
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?

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 (

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

    ), 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 (

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

    ), 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).


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?


If you use the web developer plugin, you can disable all java script from running on the page then use firebug as you wish.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消