I worked around this by calling postMessage() from my WebWorker to get the log message into the browser window where it could be logged:
// inside render-worker.js
function log(msg) {
postMessage("log: " + msg);
}
and in the code that calls the worker, I added this to the onmessage callback:// inside UI code running in the main browser window
worker.onmessage = function(e) {
if (e.data.indexOf("log:") == 0) {
window.console.log(e.data);
return;
}
// assume it's not a log message, JSON.parse() it,
// or do other stuff with it here.
}
Voila- logging from inside a WebWorker. Totally a hack, but it worked for me in a pinch.

0 comments:
Post a Comment