You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This updates worker inspector handling so Chrome dedicated Node DevTools can discover and attach to Deno workers, then route flattened worker-session protocol messages correctly.
The main changes are:
expose worker targets through Target.getTargets;
support explicit Target.attachToTarget / Target.detachFromTarget;
preserve worker sessionId routing for Chrome flattened CDP sessions;
keep worker wait-on-start behavior so debugger; in a worker can pause before subsequent code runs.
target/debug/deno test --config tests/config/deno.json --no-check -A tests/unit/inspector_test.ts --filter inspector_worker_
target/debug/deno test --config tests/config/deno.json --no-check -A tests/unit/inspector_test.ts --filter inspector_node_worker
Manual Chrome smoke test via chrome://inspect: resumed main script, DevTools showed worker [1] paused in Threads and stopped on the worker debugger; statement before after debugger printed.
Worker debugger; pausing is racy — only works by timing luck
I dug into the worker-pause path and found that the headline behavior (debugger; in a worker pauses) is timing-dependent. It reproduces as a heisenbug: it fails normally, but starts "working" the moment you add any logging to the inspector message pump (the extra I/O perturbs the timing).
Root cause: Chrome's dedicated Node DevTools auto-attaches with waitForDebuggerOnStart: false:
should_wait_for_debugger_on_worker_start() only returns true when that flag is true, so the worker boots and runs user code immediately, concurrently with Chrome enabling the debugger on the worker session. The worker can execute debugger; before its V8 debugger agent is armed, in which case V8 treats it as a no-op.
CDP trace (worker -> frontend, in emission order) showing the worker running ahead of Debugger.enable:
[worker->fe] Runtime.consoleAPICalled "Worker received: start" // onmessage already running
...flood of Debugger.scriptParsed...
[worker->fe] {"id":48,"result":{"debuggerId":...}} // Debugger.enable only completes here
[worker->fe] Debugger.paused (at debugger; line) // caught only because tracing slowed user code
Relevant detail: Chrome also sends Page.waitForDebugger to the worker, which we reject as method-not-found:
That's Chrome's intended "hold the worker until I've configured it" signal, which is presumably why it's comfortable sending waitForDebuggerOnStart: false. We ignore it, so nothing holds the worker.
Why it's not a one-line fix: simply waiting whenever auto-attach is enabled (ignoring the flag) would hang debuggers that attach but never send Runtime.runIfWaitingForDebugger to the worker session. The inspector_worker_debugger_statement_not_blackboxed test added in this PR is exactly that shape, so it would deadlock.
Possible directions (your call):
Implement Page.waitForDebugger on the worker to honor Chrome's explicit hold signal.
Pause worker-on-start whenever a target/auto-attach client is attached, releasing on the runIfWaitingForDebugger Chrome does send to the worker session, with a guard so non-resuming clients don't hang.
Happy to help validate whichever approach you pick.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #35624.
This updates worker inspector handling so Chrome dedicated Node DevTools can discover and attach to Deno workers, then route flattened worker-session protocol messages correctly.
The main changes are:
Target.getTargets;Target.attachToTarget/Target.detachFromTarget;sessionIdrouting for Chrome flattened CDP sessions;debugger;in a worker can pause before subsequent code runs.Validation:
cargo build -p denotarget/debug/deno fmt --check tests/unit/inspector_test.tstarget/debug/deno test --config tests/config/deno.json --no-check -A tests/unit/inspector_test.ts --filter inspector_worker_target/debug/deno test --config tests/config/deno.json --no-check -A tests/unit/inspector_test.ts --filter inspector_node_workerchrome://inspect: resumed main script, DevTools showedworker [1] pausedin Threads and stopped on the workerdebugger;statement beforeafter debuggerprinted.