Skip to content

Conversation

@jjspace
Copy link
Contributor

@jjspace jjspace commented Nov 4, 2025

Description

There's been a long standing issue that that console function wrappers we use in sandcastle do not pass along multiple arguments. This has always really frustrated me so while I was in the code for #13013 I also expanded support for this.

  • console.log, console.warn and console.error all now pass multiple arguments out of the iframe to the console mirror
  • Expanded support for various specific argument types including:
    • Arrays now include [] and spaces
    • Objects now log all "top level" properties to display some values without huge json blobs and not just [object Object]
    • Functions now display some of their signature. only the name when inside arrays and objects
  • Shifted logic for error line numbers into the wrapper itself instead of App code
    • This makes it much easier to handle multiple arguments that may have Error objects mixed in but it does break the ability to pass the lineNumber out of the iframe. I have some thoughts about how to address that when we get around to adding editor line highlighting back but for now I wanted to avoid bloating this PR even more.

Overall the goal is not to perfectly match what shows in DevTools but give a "good enough" approximation that's usable for developers. I don't think it's worth the effort (right now) to implement all the logic and UI needed to explore objects and nested values and everything else that DevTools can do.

Issue number and link

Fixes #11141
Also part of #12894

Testing plan

  • Open sandcastle locally or in CI
    • This is the sandcastle I tested with: Many log statements
    • carefully match the output with the input and your expectations
  • Create a sandcastle that has any number and mix of console.log, console.warn and console.error calls
  • Make sure to test with multiple arguments and multiple argument types.

Author checklist

  • I have submitted a Contributor License Agreement
  • I have added my name to CONTRIBUTORS.md
  • I have updated CHANGES.md with a short summary of my change
  • I have added or updated unit tests to ensure consistent code coverage
  • I have updated the inline documentation, and included code examples where relevant
  • I have performed a self-review of my code

@jjspace jjspace requested review from ggetz and mzschwartz5 November 4, 2025 22:11
@github-actions
Copy link

github-actions bot commented Nov 4, 2025

Thank you for the pull request, @jjspace!

✅ We can confirm we have a CLA on file for you.

Copy link
Contributor

@mzschwartz5 mzschwartz5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome improvement. It is a shame that it doesn't support nested objects... I wonder if there's a way to directly mirror the output from devtools console, rather than wrapping the console methods and trying to parse the args ourselves.

Or if there's a library that specializes in parsing console statements. (A brief search didn't yield anything for me though)

@jjspace
Copy link
Contributor Author

jjspace commented Nov 7, 2025

Or if there's a library that specializes in parsing console statements. (A brief search didn't yield anything for me though)

There's a decent chance there's a library that could do all the console mirroring for us but I haven't put much time into researching it.

It is a shame that it doesn't support nested objects...

It's certainly something we could do but I felt it would be better to put some limitation on it. It's possible more levels would help in a majority of cases. However I think with the current implementation of always needing to convert to a string for output allowing infinite nesting could be extremely excessive. I also wanted to completely ignore any sort of circular dependency handling.

@mzschwartz5 mzschwartz5 merged commit d4582b5 into clear-console Nov 7, 2025
10 checks passed
@mzschwartz5 mzschwartz5 deleted the multiple-console-args branch November 7, 2025 15:57
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.

3 participants