Skip to content

fix(ext/web): forward console.group label to inspector log#34341

Merged
littledivy merged 4 commits into
mainfrom
orch/divybot-206
May 29, 2026
Merged

fix(ext/web): forward console.group label to inspector log#34341
littledivy merged 4 commits into
mainfrom
orch/divybot-206

Conversation

@divybot

@divybot divybot commented May 24, 2026

Copy link
Copy Markdown
Contributor

Summary

console.group(label) opens a startGroup event on the V8 inspector, but
Chrome DevTools renders the group container with no visible label unless it
also receives a paired log event carrying that label — which is what Node's
console does. Deno's group previously called this.log(label), but because
the methods are arrow class fields the lexical this is the original
Console instance, so this.log resolved to the unwrapped log and never
reached the inspector. The result was a startGroup event with no following
log, and DevTools displayed empty nested containers that visibly drifted
out of alignment with the CLI output.

The fix stashes a reference to the namespace object returned from the
constructor and routes the label log through it, so when the inspector wraps
console methods, group invokes the wrapped log that fans out to both
the V8 console binding and the printer. This matches Node — inspector
captures for the issue's repro script now produce:

startGroup test1 / log test1 / startGroup test2 / log test2 / ...

instead of just:

startGroup test1 / startGroup test2 / ...

Closes #30176. Closes denoland/orchid#206.

Note: a prior attempt (#32869) tried to remove the this.log call inside
group, on the theory that the duplicate inspector event was the bug. That
theory was inverted — this.log was already silently not hitting the
inspector at all because of the arrow-function this, and DevTools was
showing an empty group as a result. This PR makes group reliably reach the
wrapped log, which is the inspector signal DevTools is looking for.

Test plan

  • New unit test consoleGroupForwardsLabelToWrappedLog in
    tests/unit/console_test.ts simulates the inspector wrap with a spy v8
    console and asserts both group and log events fire with the label
    while the CLI indentation stays unchanged.
  • New integration test inspector_console_group_emits_label_log in
    tests/unit/inspector_test.ts runs a real --inspect-brk session, drives
    the CDP socket, and asserts the Runtime.consoleAPICalled event stream
    has the matching log/startGroup pairs DevTools needs.
  • All existing console_test.ts tests pass (87 passed, 0 failed) — CLI
    output of console.group and indentation are unchanged.

`console.group(label)` opens a startGroup event on the V8 inspector,
but Chrome DevTools renders the group container with no visible label
unless it also receives a paired `log` event carrying that label —
which is what Node's console does. Deno's `group` previously called
`this.log(label)`, but because the methods are arrow class fields the
lexical `this` is the original Console instance, so `this.log`
resolved to the *unwrapped* log and never reached the inspector. The
result was a startGroup event with no following log, and DevTools
displayed empty nested containers that visibly drifted out of
alignment with the CLI output.

Stash a reference to the namespace object returned from the
constructor and route the label log through it, so when the inspector
wraps console methods, `group` invokes the wrapped `log` that fans
out to both the V8 console binding and the printer.

Closes denoland/orchid#206

Co-Authored-By: Divy Srivastava <[email protected]>
@divybot divybot changed the title deno: fix DevTools console.group indentation fix(ext/web): forward console.group label to inspector log May 24, 2026
divybot and others added 3 commits May 24, 2026 21:02
The previous --inspect-brk pattern needed an extra Debugger.resume
round-trip after Debugger.paused to actually run the script; without
it, the script stayed paused on first line and never emitted the
console events the test was waiting on. This race showed up as a
1m timeout on debug aarch64 runners. --inspect-wait pauses until
Runtime.runIfWaitingForDebugger is called, which is what the test
already sends — matching the pattern in inspector_wait.

Co-Authored-By: Divy Srivastava <[email protected]>
@littledivy
littledivy merged commit 6a701f0 into main May 29, 2026
136 checks passed
@littledivy
littledivy deleted the orch/divybot-206 branch May 29, 2026 01:58
littledivy added a commit to crowlKats/deno that referenced this pull request Jun 10, 2026
…34341)

## Summary

`console.group(label)` opens a `startGroup` event on the V8 inspector,
but
Chrome DevTools renders the group container with no visible label unless
it
also receives a paired `log` event carrying that label — which is what
Node's
console does. Deno's `group` previously called `this.log(label)`, but
because
the methods are arrow class fields the lexical `this` is the original
`Console` instance, so `this.log` resolved to the *unwrapped* `log` and
never
reached the inspector. The result was a `startGroup` event with no
following
`log`, and DevTools displayed empty nested containers that visibly
drifted
out of alignment with the CLI output.

The fix stashes a reference to the namespace object returned from the
constructor and routes the label log through it, so when the inspector
wraps
console methods, `group` invokes the *wrapped* `log` that fans out to
both
the V8 console binding and the printer. This matches Node — inspector
captures for the issue's repro script now produce:

```
startGroup test1 / log test1 / startGroup test2 / log test2 / ...
```

instead of just:

```
startGroup test1 / startGroup test2 / ...
```

Closes denoland#30176. Closes denoland/orchid#206.

Note: a prior attempt (denoland#32869) tried to *remove* the `this.log` call
inside
`group`, on the theory that the duplicate inspector event was the bug.
That
theory was inverted — `this.log` was already silently *not* hitting the
inspector at all because of the arrow-function `this`, and DevTools was
showing an empty group as a result. This PR makes `group` reliably reach
the
wrapped `log`, which is the inspector signal DevTools is looking for.

## Test plan

- [x] New unit test `consoleGroupForwardsLabelToWrappedLog` in
`tests/unit/console_test.ts` simulates the inspector wrap with a spy v8
  console and asserts both `group` and `log` events fire with the label
  while the CLI indentation stays unchanged.
- [x] New integration test `inspector_console_group_emits_label_log` in
`tests/unit/inspector_test.ts` runs a real `--inspect-brk` session,
drives
the CDP socket, and asserts the `Runtime.consoleAPICalled` event stream
  has the matching `log`/`startGroup` pairs DevTools needs.
- [x] All existing `console_test.ts` tests pass (87 passed, 0 failed) —
CLI
  output of `console.group` and indentation are unchanged.

---------

Co-authored-by: divybot <[email protected]>
Co-authored-by: Divy Srivastava <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inspect with DevTools Shows Misaligned Indentation with console.group in Deno Scripts

2 participants