Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Web Worker Error Handling
<output id="error" style="color: red;"></output>
<output id="result"></output>
function onError(e) {
document.getElementById('error').textContent = [
'ERROR: Line ', e.lineno, ' in ', e.filename, ': ', e.message].join('');
function onMsg(e) {
document.getElementById('result').textContent =;
var worker = new Worker('workerWithError.js');
worker.addEventListener('message', onMsg, false);
worker.addEventListener('error', onError, false);
worker.postMessage(); // Start worker without a message.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment