How to debug web workers

前端 未结 12 1120
被撕碎了的回忆
被撕碎了的回忆 2020-12-05 09:02

I have been working with web workers in HTML 5 and am looking for ways to debug them. Ideally something like the firebug or chrome debuggers. Does anyone have any good solu

12条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 09:44

    The accepted answer is not really a solution for everyone.

    In that case you can use console.log or console.debug or console.error in Web Workers in Firefox. See Bug #620935 and Bug #1058644.

    and If you are in Chrome, You can debug web workers just like you would debug normal scripts, the console.log will print to your tab if you do. But in case your worker is a shared one, you might want to have a look at chrome://inspect.

    Extra Tip: Because Workers are quite difficult to learn for people new to javascript, I've wrote an extremely lightweight wrapper for them that provides you a consistent API across both type of workers. It's called Worker-Exchange.

提交回复
热议问题