简体   繁体   English

使用Firefox调试短暂的Web工作者

[英]Debugging short-lived web workers with Firefox

Firefox allows to attach to web workers. Firefox允许附加到网络工作者。 You can go to about:debugging , see the list of active workers, and click on "debug" to attach. 您可以转到about:debugging ,查看活动工作程序列表,然后单击“ debug”进行附加。

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.) (至少,我还没有找到一种方法。例如,使用debugger语句设置断点在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. 作为非常粗略的解决方法,我可以使用setTimeout延迟Web worker的启动,因此我可以花时间打开about:debugging并附加到新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; 我已经创建了一个非常简单的webworker jsfiddle和debugger; works in the chrome debug tools, but not in firefox debug tools : https://jsfiddle.net/ckprrLxz/2/ 在chrome调试工具中有效,但在Firefox调试工具中无效: https : //jsfiddle.net/ckprrLxz/2/

Currently, it is not possible. 目前,这是不可能的。 At least not in Firefox 54. 至少在Firefox 54中没有。

As a workaround, I would recommend to modify the code so that web workers are reused, at least during debugging. 作为一种解决方法,我建议修改代码,以便至少在调试期间重用Web Worker。 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). 例如,通过为Web Worker代码编写测试(无论如何可能是个好主意)。

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. 从理论上讲,使用setTimeout延迟将消息发送到新创建的Web Worker也是一种选择,因为它使您有时间连接调试器。 It is certainly not ideal, but it can be used as a last resort. 这当然不是理想的,但是可以用作最后的手段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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