Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript: changing timeout for infinite loops?

Sometimes I make mistakes and get infinite loops in JavaScript (example: while(true){}). Firefox helpfully reports "Error: Script terminated by timeout" or that the memory allocation limit is exceeded. How can I change the length of this timeout? I want to shorten it during development.

I could also solve this problem by writing a function that I call inside the loop that counts iterations and throws an exception on too many iterations. But I'm also interested in how to change the timeout value.

I have not seen this timeout documented, and have not found it by searching.

like image 663
David Spector Avatar asked Aug 23 '26 08:08

David Spector


1 Answers

Unfortunately the maximum recursion limit is not user configurable from within a page running javascript. The limits also vary across browsers.

This Browserscope test showcases the results of user testing from another StackOverflow question on the subject: What are the js recursion limits for Firefox, Chrome, Safari, IE, etc?

Aside from writing your own timeout or utilising a promise chain to process data, you won't be able to change the timeout yourself.

like image 138
samthecodingman Avatar answered Aug 26 '26 00:08

samthecodingman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!