How to debug shared webworkers?

怎甘沉沦 提交于 2020-07-08 04:07:40

问题


I am using shared webworkers, I am not getting the errors from the worker. The worker error handler not returning any errors!. How can I Debug shared webworkers.

var worker = new SharedWorker('Vult_worker.js');
    worker.port.start();
    worker.port.onerror = function(e) {
        consloe.log('ERROR: Line ', e.lineno, ' in ', e.filename, ': ', e.message);
    }

    worker.port.onmessage = function(e) {
        console.log(e.data);
    };
worker.port.postmessage();

worker Code:

onconnect = function(e) {
    var self = e.ports[0];
self.onmessage=function(){
self.postmessage(1/x);
}

回答1:


Navigate to chrome://inspect/#workers and find the shared worker and click on "inspect". Then you can pull up the console for the SharedWorker.




回答2:


The accepted answer is kinda old, Since then, Mozilla Firefox has implemented console.log in Shared Web Workers and Service Web Workers. See Bug #1058644.



来源:https://stackoverflow.com/questions/11101834/how-to-debug-shared-webworkers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!