console icon indicating copy to clipboard operation
console copied to clipboard

Specify console.context

Open nchevobbe opened this issue 7 months ago • 6 comments

This specifies the console.context(label) method which returns a new console namespace object with an optional context name label.

Tests: TODO

Fixes #193


  • [x] At least two implementers are interested (and none opposed):
    • Chrome is shipping the method already
    • Mozilla is interested
  • [ ] Tests are written and can be reviewed and commented upon at:
    • TODO (waiting to get some feedback on the PR before looking into writing tests)
  • [x] Implementation bugs are filed:
    • Chromium: https://issues.chromium.org/issues/40523727
    • Gecko: https://bugzilla.mozilla.org/show_bug.cgi?id=1948870
    • Node.js: https://github.com/nodejs/node/issues/56634 (Node.js does have support for console.context() but logging with returned instance doesn't print anything. Linked issue mentions the lack of spec for the method).
    • WebKit: https://bugs.webkit.org/show_bug.cgi?id=293768
    • Deno:https://github.com/denoland/deno/issues/29560
  • [x] MDN issue: https://github.com/mdn/mdn/issues/692
  • [x] The top of this comment includes a clear commit message to use.

Preview | Diff

nchevobbe avatar May 26 '25 12:05 nchevobbe

These are drive-by comments. I don't have enough context to do a full review.

Thanks! I included your suggestions 👍

nchevobbe avatar May 26 '25 13:05 nchevobbe

looks like I overlooked what a namespace object is, and I don't think it can be what is returned from console.context() here. So I guess it should return some kind of Console/Context/ConsoleInstance interface, that hopefully we can then reuse for the definition of the console namespace?

nchevobbe avatar May 27 '25 12:05 nchevobbe

So I guess it should return some kind of Console/Context/ConsoleInstance interface, that hopefully we can then reuse for the definition of the console namespace?

What does Chromium do? Maybe @bmeurer knows?

domfarolino avatar Jun 07 '25 19:06 domfarolino

I'm happy to keep the design discussion in https://github.com/whatwg/console/issues/193, since that's where most of it has been so far. Just wanted to point out that given https://github.com/whatwg/console/issues/193#issuecomment-2952919359, I think we need to think harder about how to specify the interaction between internal state like the group stack and the notion of multiple console objects (whether they come from different documents, or the same document via .context()).

domfarolino avatar Jun 07 '25 19:06 domfarolino

So I guess it should return some kind of Console/Context/ConsoleInstance interface, that hopefully we can then reuse for the definition of the console namespace?

What does Chromium do? Maybe @bmeurer knows?

That's basically what Chromium does, see builtins-context.cc.

bmeurer avatar Jun 10 '25 08:06 bmeurer

I did something very simple here, defining a ConsoleContext interface with its own webidl, linking the methods to the one already defined for the console namespace object.

Let me know if there's something better we can do, for example, i'm not sure it's okay that the methods definition for both console and ConsoleContext are still under the console "section".


I'm happy to keep the design discussion in #193, since that's where most of it has been so far. Just wanted to point out that given #193 (comment), I think we need to think harder about how to specify the interaction between internal state like the group stack and the notion of multiple console objects (whether they come from different documents, or the same document via .context()).

For now, I'm aiming at specifying what's shipping in Chrome in the sake of moving this forward, and we can have discussions in specific issues regarding the questions that this brings (I think that's okay, context() doesn't add entirely new problems, we already have those with multiple documents)

nchevobbe avatar Nov 17 '25 08:11 nchevobbe