O'Reilly logo

HTML5 Web Application Development By Example Beginner's guide by J.M. Gustafson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Debugging web workers

Debugging web workers can be difficult. You don't have access to the window object so you can't call alert() to display a message or console.log() to write out to the browser's JavaScript console. You can't write out a message to the DOM either. You can't even attach a debugger and step through the code. So what's a poor developer to do?

One thing you can do is add an error listener to the worker, so you get notified of any errors inside the worker's thread:

worker.addEventListener("error", function(e)
{
    alert("Error in worker: " + e.filename + ", line:" + e.lineno + ", " + e.message);
});

The event object passed into the error handler contains the filename, lineno, and message fields. From those you can tell exactly where an ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required