PostMessage call in Web Worker onmessage calls SYNTAX_ERR callback: DOM 12 exception

When I write an onmessage callback for a web worker, I get the message "Uncaught Error: SYNTAX_ERR: DOM Exception 12" in my console when I try to send another postMessage () message.

var w = new Worker(url); w.onmessage = function(e) { if(e.data.msg=='validate'){ if(validateWork(e.data.wrk)){ postMessage('proceed'); } } } 
+4
source share
2 answers

You must call postMessage () using this when in a callback.

 this.postMessage('proceed'); 
+2
source

I think this will work too:

w.postMessage ('go over');

0
source

Source: https://habr.com/ru/post/1391592/


All Articles