Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not possible to debug worker #13572

Open
jonek opened this issue Feb 2, 2022 · 8 comments
Open

Not possible to debug worker #13572

jonek opened this issue Feb 2, 2022 · 8 comments
Assignees
Labels
feat new feature (which has been agreed to/accepted) inspector related to the inspector integration

Comments

@jonek
Copy link

jonek commented Feb 2, 2022

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?

@bartlomieju bartlomieju self-assigned this Feb 2, 2022
@bartlomieju bartlomieju added the inspector related to the inspector integration label Feb 2, 2022
@jonek
Copy link
Author

jonek commented Feb 2, 2022

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:

false,

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.

@bartlomieju
Copy link
Member

@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.

@stale
Copy link

stale bot commented Apr 3, 2022

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.

@stale stale bot added the stale label Apr 3, 2022
@kitsonk kitsonk added the feat new feature (which has been agreed to/accepted) label Apr 3, 2022
@stale stale bot removed the stale label Apr 3, 2022
@vazexqi
Copy link

vazexqi commented Aug 26, 2022

@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.

Screen Shot 2022-08-26 at 11 11 49 AM

@bartlomieju
Copy link
Member

This is something I will be tackling in October as I'm OOO for the next two weeks.

@bartlomieju
Copy link
Member

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.

@ntotten
Copy link

ntotten commented May 25, 2023

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.

@jespertheend
Copy link
Contributor

I managed to trigger a breakpoint from code run in a worker.

  • In chrome://inspect/#devices I clicked 'inspect' below 'deno - worker-0'
  • Then I opened the file I wanted to debug in the inspector
  • A notification popped up stating 'This script is on the debugger's ignore list'
  • I clicked 'Remove from ignore list' which seems to untoggle the 'Content scripts injected by extensions' preference
  • Then I placed my breakpoint and the debugger paused once it hit that breakpoint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat new feature (which has been agreed to/accepted) inspector related to the inspector integration
Projects
None yet
Development

No branches or pull requests

6 participants