4

I have some JavaScript that, I believe, is stuck in an infinite loop. I know I can just reload the page, but I have data in a form on the current page that I'd like to keep. The tab is completely unresponsive, so I can't just copy and paste everything and then reload. So is there any way to kill the javascript thread, but keep the DOM in Chrome?

bigblind
  • 12,539
  • 14
  • 68
  • 123
  • 1
    "Is there any way to kill the javascript thread, but keep the DOM in Chrome?" Nope. You just got to fix your infinite loop. – Mike Cluck Oct 24 '16 at 19:59
  • After thirty seconds Chrome gives you the chance to stop the executing script. You can recover the information then. – BCartolo Oct 24 '16 at 20:00
  • Here's the painful issue... The infinite loop is in a codepen.io pen. So if I reload, I lose a lot of the code that actually caused the infinite loop. – bigblind Oct 24 '16 at 20:01
  • As @BCartolo mentioned, you should get a prompt to kill it. If not, I guess take a screen shot and capture as much of the code as you can... – dmeglio Oct 24 '16 at 20:02
  • If you are writing lots of things on the web it's a good idea to use this extension: https://chrome.google.com/webstore/detail/lazarus-form-recovery/loljledaigphbcpfhfmgopdkppkifgno – BCartolo Oct 24 '16 at 20:03
  • An advice, program in your IDE, SublimeText, Atom, VSCode, and then use online tool to test your code, that way you lose less time ;) – jherax Oct 24 '16 at 20:04

3 Answers3

3

Open chrome developer tools and go to the sources tab. On the right panel press "pause script execution".

enter image description here

Josué Zatarain
  • 791
  • 6
  • 21
  • 1
    Then click-and-hold on the *Play* button and choose *Stop* from the drop-down menu in order to stop the script execution. – niutech Dec 03 '18 at 15:03
  • @nuitech - how do you click Stop when mouse is already on click-and-hold, the moment you release it to stop the execution it doesn't work, why is there no stop button, i mean really now? – user3560827 Apr 06 '19 at 13:37
3

You can open the developer console F12 and stop the scriptenter image description here

Black
  • 18,150
  • 39
  • 158
  • 271
1

looks like someone had the same problem

Cancel infinite loop execution in jsfiddle

Answer:

With the developer mode, go into resources and find your script and copy and paste it into a text document or a new window. If you can't find it in resources, do a search for a variable or line of code you used.

Community
  • 1
  • 1
Bimbonkens
  • 319
  • 3
  • 11