在 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. Google Chrome (v22) 運行該腳本。 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:與刷新相同。
  • 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 年多和近 1 萬次瀏覽,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 的回答。


解決方案:

參考一: https://en.stackoom.com/question/t6wN
參考二: https://stackoom.com/question/t6wN
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章