1

I started to make a simple js debugger, and I was wondering if there is a way to stop an already running script if either it isn't responding or I want to stop it's setInterval() loop where we don't know the id of the loop.


I've noticed in the Chrome DevTools that every document has it's own script collection under document.scripts, but I couldn't find anything like a list of intervals (eg:window.intervals) or any response if any function is running,so I can't really determine if a function needs to be killed.


This could be useful when you want a webpage scanner extension or a debugger thet can refresh the page when the script is frozen.

Edit:

The list of intervals has already been asked and solved in How can I get all timers in javascript question.

Now the only question remains is: How can I determine if a script is frozen so it or the page can be killed?

Szecska
  • 11
  • 1
  • 5
  • Intervals and timers are set on the `window` object, not scoped to individual scripts. – Terry Mar 15 '20 at 22:40
  • Oh, you're right! But still there is no list that keeps track of them – Szecska Mar 15 '20 at 22:43
  • Does this answer your question? [How can I get all timers in javascript?](https://stackoverflow.com/questions/46014061/how-can-i-get-all-timers-in-javascript) – Terry Mar 15 '20 at 22:45
  • I corrected the question, thanks! – Szecska Mar 15 '20 at 22:45
  • If it's totally frozen then I believe there is nothing you can do from JS. JS is single-threaded so infinite loop will freeze it all, no way to kill it from other JS on a web page. On the other side if you make a plugin then there is a debugger API with sendCommand method that might be useful. – Zbyszek Mar 15 '20 at 23:09
  • So there is no way to shut a script down. Thanks – Szecska Mar 20 '20 at 23:22

0 Answers0