简体   繁体   English

如何使用JavaScript防止浏览器出现错误消息?

[英]How to prevent error messages at the browser using JavaScript?

I'm writing a web application which conducts calculations that stress the browser and the computer's CPU. 我正在编写一个Web应用程序,该应用程序进行的计算会给浏览器和计算机的CPU造成压力。

The program should act as follows, and the stressing is not something that is the problem, or needs to be solved. 该程序应按以下方式操作,而强调不是问题或需要解决的问题。

I would like to prevent the browser (Chrome and Firefox especially) from popping up an error message such as 'page is unresponsive' . 我想防止浏览器(尤其是Chrome和Firefox)弹出诸如“页面无响应”之类的错误消息。

How can I do it using javaScript? 如何使用javaScript做到这一点?

I prefer not to change browser setting (I don't want that users of the app have to change Chrome settings manually). 我不希望更改浏览器设置(我不希望应用程序的用户必须手动更改Chrome设置)。

check this developer tools in Chrome 在Chrome中查看此开发者工具

chrome://chrome-urls/

Go to For Debug 去调试

Might help in case of Chrome 如果使用Chrome,可能会有所帮助

Have a look at the Webworkers: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers 看看Webworkers: https : //developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers

Those run in threads in the background and are designed for heavy load tasks. 那些在后台线程中运行,并且设计用于繁重的任务。

You should break up the task into pieces if possible (see this question ) and delegate out the work to Web Workers . 如果可能,您应该将任务分解(请参阅此问题 ),然后将工作委托给Web Workers

Using Web Workers is pretty simple, you just specify the URI of the script you want to run ( main.js ): 使用Web Workers非常简单,您只需指定要运行的脚本的URI( main.js ):

var myWorker = new Worker('worker.js');

To communicate with the worker, you pass messages back and forth. 要与工作人员进行交流,您需要来回传递消息。 To send a message to the worker, call myWorker.postMessage ( main.js ): 要将消息发送给工作人员,请调用myWorker.postMessagemain.js ):

myWorker.postMessage('some value');

To receive messages on the worker, define an onmessage handler like this. 要在工作程序上接收消息,请定义这样的onmessage处理程序。 You can also postMessage back to the main thread ( worker.js ): 您还可以将postMessage回到主线程( worker.js ):

onmessage = function(e) {
  // e.data === 'some value'
  console.log('Message received from main script');
  postMessage('worker result');
}

Back in your main thread, you can listen for messages from your worker like this ( main.js ): 回到主线程,您可以像这样( main.js )侦听来自工作人员的消息:

myWorker.onmessage = function(e) {
  // e.data === 'worker result'
  console.log('Message received from worker');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM