Open jonek opened 2 years ago
This is the main.js
I used:
console.log('main: started');
debugger;
const myWorker = new Worker(new URL("./worker.js", import.meta.url).href, { type: "module" });
console.log('main: spawned', myWorker);
This is the worker.js
:
try {
console.log('worker: hello from worker');
debugger;
} catch(e) {
console.error('error', e);
}
I also found this: https://github.com/denoland/deno/blob/1fb5858009f598ce3f917f9f49c466db81f4d9b0/runtime/web_worker.rs#L448
It seems to indicate, that the inspector will never stop in worker code.
I launched Deno with --inspect-brk
.
VSCode was showing either the output of the main worker or the output of the worker in the debugger view. It seemed to choose either one indeterministically.
@jonek that flag only indicates that debugger shouldn't break on the first line of worker code. I will verify how it works in VSCode, but in Chrome Devtools (chrome://inspect
) once the worker is launched you will see a new entry show up that allows you to connect to it.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.
@bartlomieju - Any updates on this? Is this a limitation of deno? Or, of the deno VS Code extension?
I have only been able to get this to work if I use it with the Chrome Devtools (chrome://inspect
) but I was hoping to have it work inside VS Code.
This is something I will be tackling in October as I'm OOO for the next two weeks.
FYI I'm investigating this issue - it turned out to be much more complex than I expected. The way it works for Node is by using a custom "NodeWorker" domain for Chrome Devtools Protocol that is not really standardized. I will try to get in touch with VSCode team to see if there's a way forward to make it work more like in browser, if that won't be possible we'll look into using the same mechanism as Node does.
Anyone interested in working on this on a sponsored basis? This is a major annoyance, but I’m not at all familiar with the internals at this level so I’d be willing to fund this work. Let me know.
I managed to trigger a breakpoint from code run in a worker.
chrome://inspect/#devices
I clicked 'inspect' below 'deno - worker-0'To my surprise I found a workaround to get worker breakpoints to hit in VSCode.
Unfortunately this is still highly inconsistent, I think the debugger accidentally attaches to the same process twice a lot of the time. If anyone knows how to explicitly have the ports between main and workers be different or different ws addresses let me know. https://github.com/mommysgoodpuppy/DenoDebugWebworkersExample
It seems the debugger in VSCode and Chrome never stops at breakpoints in worker code.
Are there any variables, specific Deno command line flags or worker options I have to use to be able to debug worker code?