Have you ever written an infinite loop that freezes an entire page in your browser?
In this article, I will try to show you how to deal with such a problem.
Before we start, I would highly recommend you to check out the original post with the solution on our website:
Stop infinite loop in JavaScript debugger - Google Chrome
Now let's go to the solution 😊🔽
Using Google Chrome, there are few ways to stop JavaScript debugging:
- stop button in Chrome DevTools,
- end process by closing tab or window,
- end process button in Task manager.
1. Stop button in Chrome DevTools example ⏯🛑
📝 Note:
To use this approach DevTools should be turned on before JavaScript code will be executed. Otherwise you won't be able to open the tools with F12 because Chrome window will freeze. You will still be able to turn on the tools with browser menu, but the tools won't connect to the executing source code to stop it - in this case, code execution can only be stopped by closing a tab or window. Sometimes, with a low amount of RAM or a large amount of open tabs, DevTools may have trouble with stopping the infinity loop
There are several steps you need to take to get this done:
- open Chrome DevTools with F12, Ctrl+Shift+i or from menu Main menu→More tools→Developer tools,
- open web page that you want to debug,
- run some code that has infinity loop,
- click Chrome DevTools window to get focus on it,
- pause script with F8, Ctrl+\ or by clicking Pause script execution button,
- press mouse button for 1-3 seconds on the button again to see more options,
- move click action to square stop button on expanded menu to stop permanently script execution.
2. End process by closing tab or window
Use close button to stop the process. If it does not help use Task manager described in next solution.
3. End process button in Task manager
In this solution you need to:
- open Chrome Task manager with Shift+Esc or from menu Main menu→More tools→Task manager,
- find the process on list by tab name or biggest CPU load (use column sort option),
- select process and click End process button.
If you found this solution useful let me know in the comment section or just leave a reaction 💗🦄💾.
Thanks for reading and see you in the upcoming posts! 😊🔥
Write to us! ✉
If you have any problem to solve or questions that no one can answer related to a React or JavaScript topic, or you're looking for a mentoring write to us on dirask.com -> Questions
Top comments (2)
That was useful to know. Thanks!
You're welcome 😊
Some comments may only be visible to logged-in visitors. Sign in to view all comments.