Cancel infinite loop execution in jsfiddle

2019-01-21 18:37发布

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 all 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 :-)

8条回答
时光不老,我们不散
2楼-- · 2019-01-21 19:10

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/
查看更多
Lonely孤独者°
3楼-- · 2019-01-21 19:11

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.
查看更多
登录 后发表回答