Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
406 views
in Technique[技术] by (71.8m points)

javascript - 如何在Google Chrome中调试时终止脚本执行?(How to terminate script execution when debugging in Google Chrome?)

When stepping through JavaScript code in Google Chrome debugger, how do I terminate script execution if I do not want to continue?(在Google Chrome调试器中单步执行JavaScript代码时,如果我不想继续,如何终止脚本执行?)

The only way I found is closing the browser window.(我找到的唯一方法是关闭浏览器窗口。)

Pressing "Reload this page" runs the rest of the code and even submits forms as if pressing F8 "Continue".(按“重新加载此页面”将运行其余代码,甚至提交表单,就像按F8“继续”一样。)

UPDATE :(更新 :)

When pressing F5 (Refresh) while a script is paused:(在脚本暂停时按F5(刷新):)

  • Google Chrome (v22) runs the script.(谷歌浏览器(第22版)运行该脚本。) If the script submits HTTP request, the HTTP response for that request is displayed.(如果脚本提交HTTP请求,则会显示该请求的HTTP响应。) The original page is not refreshed.(原始页面未刷新。)
  • IE 9 just freezes.(IE 9只是冻结了。) However IE has an option "Stop Debugging" which, when pressed (provided you did not press F5 earlier), continues to run the script outside debugger.(但IE有一个选项“停止调试”,当按下时(如果你之前没有按F5),继续在调试器外运行脚本。)
  • Firebug behaves identically to Chrome.(Firebug的行为与Chrome相同。)

Closing and then opening again the browser window is not always the next easiest way because it will kill browser session state and that may be important.(关闭然后再次打开浏览器窗口并不总是下一个最简单的方法,因为它会终止浏览器会话状态,这可能很重要。)

All your breakpoints are also lost.(你的所有断点都会丢失。)

UPDATE (Jan 2014) :(更新(2014年1月) :)

Refresh while debugging:(调试时刷新:)

  • Chrome v31: lets scripts to run and stops on further breakpoints (but does not submit ajax requests), then refreshes.(Chrome v31:允许脚本在更多断点上运行和停止(但不提交ajax请求),然后刷新。)
  • IE 11: refresh does nothing, but you can press F5 to continue.(IE 11:刷新什么都不做,但你可以按F5继续。)
  • Firefox v26: lets scripts to run but does not stop on further breakpoints, submits ajax requests, then refreshes.(Firefox v26:让脚本运行但不会停留在更多断点上,提交ajax请求,然后刷新。)

Kind of progress!(有点进步!)

Navigate to the same page while debugging:(调试时导航到同一页面:)

  • Chrome v31: same as Refresh.(Chrome v31:与Refresh相同。)
  • IE 11: scripts are terminated, new browser session is started (same as closing and opening again).(IE 11:脚本终止,新的浏览器会话启动(与关闭和再次打开相同)。)
  • Firefox v26: nothing happens.(Firefox v26:没有任何反应。)

Also juacala suggested an effective workaround.(juacala也提出了有效的解决方法。)

For example, if you are using jQuery, running delete $ from console will stop execution once any jQuery method is encountered.(例如,如果您使用的是jQuery,则在遇到任何jQuery方法后,从控制台运行delete $将停止执行。) I have tested it in all above browsers and can confirm it is working.(我已在所有上述浏览器中对其进行了测试,并确认其正常运行。)

UPDATE (Mar 2015) :(更新(2015年3月) :)

Finally, after over 2 years and almost 10K views, the right answer was given by Alexander K. Google Chrome has its own Task Manager which can kill a tab process without closing the tab itself, keeping all the breakpoints and other stuff intact.(最后,经过2年以上和近10K的观看,Alexander K给出了正确的答案。谷歌Chrome有自己的任务管理器,它可以在关闭标签本身的情况下终止标签进程,保持所有断点和其他内容不变。)

I even went as far as BrowserStack.com to test it in Chrome v22 and found that this was working this way even at that time.(我甚至到了BrowserStack.com,在Chrome v22中测试它,发现即使在那个时候这种方式也是如此。)

Juacala's workaround is still useful when debugging in IE or Firefox.(在IE或Firefox中进行调试时,Juacala的解决方法仍然有用。)

UPDATE (Jan 2019) :(更新(2019年1月) :)

Chrome Dev Tools at last added a proper way to stop script execution which is nice (although a bit hidden).(Chrome Dev Tools最后添加了一种正确的方法来停止脚本执行,这很好(虽然有点隐藏)。)

Refer to James Gentes's answer for details.(有关详细信息,请参阅James Gentes的答案。)   ask by srgstm translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In Chrome, there is "Task Manager", accessible via Shift + ESC or through(在Chrome中,有“任务管理器”,可通过Shift + ESC或通过)

Menu → More Tools → Task Manager(菜单→更多工具→任务管理器)

You can select your page task and end it by pressing "End Process" button.(您可以选择页面任务,然后按“结束处理”按钮结束它。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...