HTML and CSS Reference
In-Depth Information
Debugging a worker
We've gotten to the point in web development where the tools
for debugging are so much better than ten years ago. All the lat-
est browsers come with their own JavaScript debugger (though
Firefox still requires Firebug as a plugin); it's a haven of debug-
ging when compared to the bad old days of using alert boxes
left, right, and centre.
While with a Web Worker, now you're working in a sandboxed
environment, so there is no access to the console debuggers.
There's no native way to do console.log(“who's the daddy?” ) in
a worker. To compound this hurdle, there's not even an alert box
we can use.
However! There is hope yet. The WebKit folks have kindly
thought about this problem, and in the scripts panel the devel-
oper tools offer a debug checkbox next to Web Workers (in both
Chrome and Safari). This changes how Web Workers actually
run (behind the scenes they're running in a setTimeout ), but it
does mean you can include console.log in your code to help
you debug as seen in Figure 10.3 .
FIguRE 10.3 Check the
Debug check box to allow the
developer to run console.log
inside a Web Worker.
Search WWH ::

Custom Search