简体   繁体   中英

Debugging short-lived web workers with Firefox

Firefox allows to attach to web workers. You can go to about:debugging , see the list of active workers, and click on "debug" to attach.

But what to do if the application creates a short-lived worker? I want to set a breakpoint, but I cannot do so in advance before the worker is created. (At least, I have not found a way to do so. For instance, setting a breakpoint with the debugger statement does not work in Firefox 54.)

As a very crude workaround, I can delay the startup of the web worker by using setTimeout , so I can use the time to open about:debugging and attach to the new worker. This is not a good solution, however.

Is there an efficient way to set a breakpoint in advance (before the worker is even started)?

I've forked a very simple webworker jsfiddle, and debugger; works in the chrome debug tools, but not in firefox debug tools : https://jsfiddle.net/ckprrLxz/2/

Currently, it is not possible. At least not in Firefox 54.

As a workaround, I would recommend to modify the code so that web workers are reused, at least during debugging. In my specific use case, it was relatively easy to do so. Depending on the situation, it might be more difficult or not even possible. In that case, you have to use other techniques to debug the code. For instance, by writing tests for the web worker code (which might be a good idea, anyway).

Delaying sending the message to the newly created web worker with setTimeout is theoretically also an option, as it gives you some time to attach the debugger. It is certainly not ideal, but it can be used as a last resort.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM