I'm trying to create a rotating banner (JavaScript & CSS). For debugging and making changes on the CSS etc in the developers' console, I want to pause the JavaScript execution while I make changes and then run it or so on. So, is there a way to pause the script execution in the browser?
3 Answers
As katspaugh mentions in their comment:
F8
This only works for me from the Sources tab of the Developer Tools window in Chrome 59.0.3071.115 (on Mac OS X).
Comments
You are looking for "breakpoints".
Which browser are you using?
Chrome supports breakpoints right away in its developer tools:
F12 (or Ctrl-Shift-I), "Script" tab, select script from dropdown, click the line number.
Update:
On PC: F12 or Ctrl+Shift+I / On Mac: Cmd+Alt+I
select "Sources" tab, select script from the file pane on the left, click the line number.
In Firefox use the Firebug extension:
On PC and Mac: F12,
"Script" tab, activate & reload if needed, select script from dropdown, click line number.
When your Javascript pauses at a breakpoint, both browsers offer you the usual debugging tools to single step through the code, inspect & change variable values, watch expressions,...
10 Comments
debugger; keyword in JS code to trigger their debugger. This is equivalent to setting a breakpoint in the code.You can write a pause code yourself. Pause javascript excution using debugger. In the chrome console, run:
window.addEventListener('keydown', function(event) {
if (event.defaultPrevented) {
return; // Should do nothing if the default action has been cancelled
}
let handled = false;
if (event.keyCode == 121) {
handled = true;
debugger; // 121 is the keyCode of F10
}
if (handled) {
// Suppress "double action" if event handled
event.preventDefault();
}
});
Highlight element with inspector
Hit F10