开发者

Cancel infinite loop execution in jsfiddle

开发者 https://www.devze.com 2023-04-10 09:57 出处:网络
When you get an infinite loop in jsfiddle in Chrome, your only choice (that I know of) is to close the tab.Of course, this means you lose all your work in the current window!Is there an easy way to st

When you get an infinite loop in jsfiddle in Chrome, your only choice (that I know of) is to close the tab. Of course, this means you lose all your work in the current window! Is there an easy way to stop an infinitely executing script?

  1. I have the developer tools open because I was doing some debugging.
  2. I am able to pause the script and step through the loop.
  3. I can't find anywhere to stop the script.
  4. I can't modify the script or variables to stop the infinite loop (because the script execution occurs in an iframe on a separate domain, so modifying data in the iframe with JavaScript is not allowed and generates an Exception in the console).

It al开发者_JS百科l started because I decided to swap directions on my loop from

for (var c = 0; c <= 11; c++)

to

for (var c = 12; c > 0; c++)

But as you can see above, I forgot to change it from c++ to c--.

Any ideas?? I still have the tab open and I'm hoping to get it back without closing the tab :-)


How to do it without Developer Mode:

  • Open a new tab
  • Open the Task Manager with Shift-Escape
  • Kill task
  • Use back button for the killed tab (JSFiddle won't run the script)
  • Fix bug
  • Update

Or on MacOS,

  • Open Activity Monitor
  • Kill the first "Google Chrome Helper (Renderer)" process. It's probably JSFiddle
  • Fix the issue
  • Run the code


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.


One way of breaking the infinite loop is to throw an unhandled exception, which will stop the execution of current call stack. To do so:

  1. pause the debbuger
  2. find a promising statement inside the loop, for example a function call: foo.bar(args)
  3. in console, overwrite the function to throw : foo.bar=function(){throw 42;}
  4. unpause the debugger

worked for me. I haven't tried, but I believe that by overloading getter or setter you can use the trick described above also for assignments and reads, not only for function calls. Also, by setting a variable to undefined, you may cause fatal error (and thus break the loop) if the field of this variable is used in the loop. For example delete foo.tab will break foo.tab[42] or foo.tab.bar. For some reason, simply writting foo=undefined in the console, will not do (perhaps it defines a variable local to the console window named foo).


Run Process Explorer and kill the chrome process that's using lots of CPU...it will "crash" the page and let you reload...


I couldn't start Chrome's Task Manager while the looping tab was active. I had to select another tab. Then I pressed Shift-Escape to launch the Task Manager, kill the JSFiddle process, re-select the tab, and hit the back button to display the page without running the script.

JSFiddle loads the "result" panel using an iframe. As of June 2016, the URL for the frame is the Fiddle URL plus "/show/". I inspected the source code of the iframe and discovered that it loads yet another URL with "/light/". One of these URLs should contain your source code.

If your browser supports the view-source URI scheme, you may access your fiddle's source code as follows:

  • view-source:jsfiddle.net/user_name/fiddle_hash/revision/light/
  • view-source:jsfiddle.net/user_name/fiddle_hash/revision/show/


Same problem came up here, I opened up the javascript console in a script paused state. (Paused it using the Developer Tools)

Then I changed the variable value so that the while loop would end.


In case others are stuck after reading the other answers, here's what worked for me (Chrome, Mac). For me the JSFiddle tab was 'stuck' but the rest of Chrome responsive. I had the JavaScript Console open on the Resources pane, but it was unresponsive too. Reloading the page in this state didn't help because JSFiddle would give me the script before I got anything at all.

In the end this worked for me; maybe it will help you too...

  • While the page is unresponsive, go to Chrome > Preferences > Privacy and disable JavaScript.
  • Wait for page to die (about 4 or 5 minutes for me); the sad face icon comes up in that tab.
  • Hit the back button. It should look like JSFiddle is loading, but it won't because funnily enough JSFiddle needs JavaScript just to render a page.
  • View > Developer > View source
  • My script, only slightly mangled, was sitting there all innocent like in a div called 'panel_js'.
  • Highlight, copy, breathe again, learn lesson.


I had file stuck in a loop and would freeze up the dashboard on JSFiddle as well.

  • The only way I could clear was to disable JavaScript in the preferences tab while I had a New Fiddle page open in a different Chrome tab.
  • Then navigate to All Fiddles.
  • Delete the Fiddle and then it would give a 404 error.
  • Turn on the JavaScript and reload the Dashboard.
  • Was able to continue on making and editing fiddles after that.
0

精彩评论

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