Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pausing code execution in chrome from within JS. Possible?

Can I pause execution from within JS code? I am working on a simple haxe-based debug util, and I want to be able to simulate breakpoints, by calling a util method which will trigger the execution pause.

like image 823
user802232 Avatar asked Nov 20 '11 09:11

user802232


People also ask

How do you pause Google Chrome?

Google's Keyboard Shortcuts Reference lists for "Pause / resume script execution": F8 or Ctrl + \ (Windows) F8 or Cmd + \ (Mac)

How do I pause HTML code?

You can insert debug() into your code (like a console. log() statement) or call it from the DevTools Console. debug() is equivalent to setting a line-of-code breakpoint on the first line of the function. let result = a + b; // DevTools pauses on this line.


1 Answers

Not sure if this is what you're looking for, but in Chrome (and Firefox if Firebug is installed) you can use the built-in JavaScript debugger statement. This causes the execution to pause, and is effectively like setting a breakpoint. For example, the following would break on every iteration of the loop allowing you to examine the value of i (stupidly simple example):

for(var i = 0; i < 10; i++) {
    debugger;
    console.log(i);
}
like image 160
James Allardice Avatar answered Oct 18 '22 15:10

James Allardice