-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
inspector: support for worker inspection in chrome devtools #56759
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
base: main
Are you sure you want to change the base?
Conversation
Review requested:
|
})); | ||
} | ||
|
||
test().then(common.mustCall()); |
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 think the test()
function wrapper is no longer needed: by default, an unhandled promise rejection makes the process exit with a non-zero exit code.
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.
Thank you.
I removed the wrapper.
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.
Sorry for the previous comment. The promise.then(common.mustCall())
pattern is still needed to handle the case where the process exits with the promise unsettled.
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.
Ah, got it — I’ll bring it back.
Tracing the history discussion, it would be great to have @eugeneo, @pavelfeldman and @dgozman weighing in this work |
Confirmed with Chrome DevTools team (dsv@, caseq@) that they are good with Node.js implementing the Target domain for worker discovery, or implementing NodeWorker domain support in Chrome DevTools frontend. As the Target domain in this PR is behind the flag |
Thank you! |
141ec5a
to
984f640
Compare
984f640
to
fafadd0
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #56759 +/- ##
==========================================
+ Coverage 89.21% 90.26% +1.05%
==========================================
Files 663 632 -31
Lines 192001 186021 -5980
Branches 36923 36442 -481
==========================================
- Hits 171290 167914 -3376
+ Misses 13582 10984 -2598
+ Partials 7129 7123 -6
🚀 New features to boost your workflow:
|
Issue to devtools-frontend |
const sessionId = '1'; | ||
await session.waitForNotification('Target.targetCreated'); | ||
await session.waitForNotification((notification) => { | ||
return notification.method === 'Target.attachedToTarget' && |
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.
Event Target.attachedToTarget
should not be emitted without a Target.setAutoAttach
command or Target.attachToTarget
command.
// TODO(islandryu): Currently, setAutoAttach applies the main thread's value to | ||
// all threads. Modify it to be managed per worker thread. | ||
crdtp::DispatchResponse TargetAgent::setAutoAttach( | ||
bool auto_attach, bool wait_for_debugger_on_start) { | ||
auto_attach_ = auto_attach; | ||
wait_for_debugger_on_start_ = wait_for_debugger_on_start; | ||
|
||
if (auto_attach) { | ||
for (auto& target : targets_) { | ||
if (!target.attached) { | ||
target.attached = true; | ||
attachedToTarget(target.worker, | ||
target.target_id, | ||
target.type, | ||
target.title, | ||
target.url); | ||
} | ||
} | ||
} |
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.
setAutoAttach is implemented.
However, I am not able to determine autoAttach for each related Target and waitForDebuggerOnStart.
I have tried several way, but it was difficult to make the changes without affecting the existing nodeWorker, so I would like to make a TODO.
); | ||
|
||
|
||
const session = await child.connectInspectorSession(); |
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.
Can you add another suite to guarantee this command will fail when --permission
is used?
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 added it below.
62315c8
to
d8747cf
Compare
Co-authored-by: Rafael Gonzaga <rafael.nunu@hotmail.com>
Co-authored-by: James M Snell <jasnell@gmail.com>
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.
Thank you for working on this! This will need change in the Chrome DevTools Frontend code as well: https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/core/sdk/ChildTargetManager.ts;l=143-188?q=ChildTargetManager.ts
Would you like to draft the change as well? Otherwise I can help with the work to land the change in devtools-frontend.
src/inspector/target_agent.cc
Outdated
const std::string& title, | ||
const std::string& url) { | ||
std::string target_id = std::to_string(getNextTargetId()); | ||
std::string type = "worker"; |
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 type conflicts with the web worker type in https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/core/sdk/ChildTargetManager.ts;l=176?q=ChildTargetManager.ts
If devtools-frontend recognize Node.js worker as a web worker, it will fail to attach to this target as Node.js does not support all domains supported by a web worker.
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.
Would you like to draft the change as well? Otherwise I can help with the work to land the change in devtools-frontend.
Thx, I have prepared a draft on my end.
https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6218804
For now, I named the new type node_worker.
Co-authored-by: Chengzhong Wu <legendecas@gmail.com>
This PR introduces support for inspecting workers in Chrome DevTools. I would like to gather some feedback to confirm whether there seem to be no issues with this approach. If the approach in this PR deviates significantly from the desired direction, I am happy to close it. However, if the general approach seems acceptable, I will proceed with this PR and submit a change request to Chrome DevTools.
Summary of Changes
This implementation uses the
attachedToTarget
event to notify the creation of workers. More details on the protocol can be found [here](https://chromedevtools.github.io/devtools-protocol/tot/Target/#event-attachedToTarget).This sequence is how to worker inspection works.
When a worker is created, attachedToTarget is notified to the server, and the server thread allocates methods from the client to the appropriate thread based on the sessionId.
How to Verify
Currently, dedicated DevTools for Node.js do not support worker targets. For verification, use
inspector.html
:Steps:
index.js
andworker.js
files for testing:index.js
:worker.js
:Currently, the results of console.log within the worker are being sent twice, but I'm working on fixing this issue.Additional Information
The approach used in this PR follows the CDP (Chrome DevTools Protocol) and is different from the Node.js worker debugging protocol used in VSCode. It adheres to the existing CDP protocol to ensure compatibility.
fix #56343