-
Notifications
You must be signed in to change notification settings - Fork 274
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
Fix step-debugging in Workerd #1480
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code in this file was extracted from mini-oxygen/workerd-inspector.ts
and hasn't changed at all. Feel free to skip it in the review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀👀👀👀 😜
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verified it works in both VSCode and Chrome. A few thoughts:
-
It does not work with a "JavaScript Debug Terminal" presumably because VSCode isn't connecting to the right port. That's unfortunate, because the JS debug terminal is convenient without needing to setup a vscode launch config. I often prefer this because the port itself is variable (if something's already on port 3000, it goes to 3001). But probably it's not that likely to boot up multiple hydrogen apps at the same time? If so, perhaps down the road we could add a CLI init question around VSCode (do you use VSCode?). And if so, then automatically generate the launch config?
-
Not in scope for this work, but it would be great if we could also support something like
--debug-brk
to automatically pause at startup.
@@ -8,6 +8,7 @@ | |||
"ci:checks": "turbo run lint test format:check typecheck", | |||
"dev": "npm run dev:pkg", | |||
"dev:pkg": "cross-env LOCAL_DEV=true turbo dev --parallel --filter=./packages/*", | |||
"dev:app": "cd templates/skeleton && cross-env LOCAL_DEV=true npm run dev", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼
...(debug | ||
? [ | ||
{ | ||
warn: `\n\nDebugger listening on ws://localhost:${inspectorPort}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is important, because the default port that chrome looks for is different than what we default to. I had to manually add 9222
for chrome to see it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const url = req.url?.split('?')[0] ?? ''; | ||
|
||
switch (url) { | ||
// We implement a couple of well known end points |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious how you knew how to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of this comes from Wrangler itself! But also it's documented in https://chromedevtools.github.io/devtools-protocol/#endpoints
Thanks for the review!
Unfortunately, the JavaScript Debug Terminal can only attach to Node.js processes, it doesn't support connecting to an independent port :/
This is interesting, maybe we could do this automatically if we detect a
I don't think we can make this work in workerd at the moment. |
This PR enables step-debugging when using
--worker-unstable
in combination with--debug
, as well as allowing external DevTools to connect to the workerd inspector.The approach is a simplified version of what Wrangler does: it adds a server proxy between the workerd and the local debugger which:
To test the debugger in VSCode, add this to
.vscode/launch.json
and start the debugger after the app is running withh2 dev --worker-unstable --debug
.To test Chrome DevTools, open
chrome://inspect
and make sure the port 9222 is added to the network targets.