Intercepting browser messages slower script

Is it possible to intercept browser messages, such as:

Firefox:

A script on this page may be busy or it may stop responding. You can now stop the script, open the script in the debugger, or continue the script.

those.

A script on this page invokes a web browser to run slowly. If it continues to work, your computer may stop responding.

These posts are due to the fact that the page has a lot of javascript / jquery activity.

I argue that the fact that these messages appear in the first place indicates a wider problem, but is there a way to influence this message / situation on the client side so that a message that is more user-friendly is possible?

+4
source share
2 answers

There is no way to do this, imagine that a malicious user is writing a script that slows down your browser until it is completely inaccessible, now the warning β€œSlow Script” may come to the rescue, but what if he can intercept it and prevent it show?

You need to find a solution to the main problem, that is, if you are doing a lot of calculations (which, I suppose, you are doing this), you need to break them into pieces, put them in queues and process them either asynchronously (if possible), either ok but with a short timeout between them.

In pseudocode, it might look like this:

var queue = []; // put your functions or the data in here function() processQueue{ if (queue.length > 0) { var item = queue.shift() // pop of the first item of the queue item(); // call the function, or in case of data pass it to th processing function setTimeout(processQueue, 100); // wait 100 ms before processing the next chunck } } setTimeout(processQueue, 0); 
+6
source

No, it is impossible to intercept these messages, they are at a lower level in the engine to protect the user. Instead, take a look at what takes so much time, optimize as much as possible ... perhaps breaking your work into pieces that have processing flaws, so you don't run messages.

+1
source

All Articles