Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deliberately freeze javascript in chrome (plugin/console)

I want to inspect elements of my page in development that disappear right after he mouse leaves them. Fot this and other scenarios I want something like a "disable JS" plugin or console-command, that works not only at pageload time, but can completely halt any and every js of the current page at any time.

Does such a solution exist? I would prefer chrome, but accept firefox. Thanks.

like image 481
Zsolt Szilagyi Avatar asked Jul 05 '13 23:07

Zsolt Szilagyi


People also ask

How do you freeze a page in JavaScript?

setTimeout = function(code, delay) { return _setTimeout(function () { if (_pauseOn == true) { return; } code(); }, delay); }; window. clearTimeout = function(intervalId) { if (_pauseOn == true) { return; } _clearTimeout(intervalId); }; window.

Can I write JavaScript in Chrome console?

You don't necessarily need to have an HTML page. Open Chrome, press Ctrl+Shift+j and it opens the JavaScript console where you can write and test your code.


2 Answers

What worked for me to pause execution:

  1. Open Chrome javascript console (Ctrl+Shift+J)
  2. Go to "sources"
  3. On the right side, click the little "pause" icon, or press F8 to pause script execution.

You can also put in "breakpoints" within the same console. Try the following to use breakpoints:

  1. Open Chrome javascript console (Ctrl+Shift+J)
  2. Go to "sources"
  3. On the right side, click the little "pause" icon, or press F8 to pause script execution.
  4. Now you can click the "Step over", "Step Into", etc functions on the right side to slowly step into the code, line by line.
  5. You can also click on the line number for any of the sources to add a breakpoint. Breakpoints will stop the code execution when it is reached. You can enable/disable breakpoints on the right side next to the other buttons mentioned above.
like image 64
Katie Avatar answered Sep 23 '22 20:09

Katie


Try using the debugger; directive (relevant MDN article). This acts like a breakpoint and should help you debug your scripts using the normal developer console.

like image 33
Andrei Bârsan Avatar answered Sep 21 '22 20:09

Andrei Bârsan