Skip to content

Instantly share code, notes, and snippets.

@jay3sh
Created August 16, 2011 15:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jay3sh/1149363 to your computer and use it in GitHub Desktop.
Save jay3sh/1149363 to your computer and use it in GitHub Desktop.
WebWorker stacktrace for debug
//
// In the WebWorker
//
function debug(msg) {
postMessage(JSON.stringify({type:'debug',msg:msg}));
}
onmessage = function (e) {
try {
var inputData = e.data;
// work on input data
// ...
// Calculate answer to the ultimate question
postMessage(JSON.stringify({type:'response', answer:42}));
} catch(e) {
var stack = e.stack.replace(/^[^\(]+?[\n$]/gm, '')
.replace(/^\s+at\s+/gm, '')
.replace(/^Object.<anonymous>\s*\(/gm, '{anonymous}()@')
.split('\n');
debug(e+'\n'+stack);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment