12

I'm working on a project where some library calls console.trace every refresh. Chrome then automaticly unfolds the trace, so that it takes over 20 lines on the console.

This takes too much space and I would much rather have it folded by default and only unfold when I click on it, like with litteraly everything else in the JS console.

Can this be done in Google Chrome, preferably without an extension? I have looked at all the option, but this seems to be impossible to disable.

1
  • 2
    You could maybe override console.trace with custom code (in the development environment only). I'm not sure if this approach can solve your problem, it's just an idea to explore.
    – thirtydot
    Commented Jul 11, 2017 at 16:16

2 Answers 2

3
+50

This is the subject of the bug-report from 2017
Issue 677929: DevTools: console.trace has expanded stack trace by default.

The bug was marked as fixed on 2018, then reported as being back on 2019, marked as fixed again, reported as being back on 2019, also reported by users as being still there on 2020 and 2021.

All these reports have not budged the bug status from "Fixed (Closed)", so there is not much hope from Chromium/Chrome. You could try to open a new bug-report.

For a workaround, you could hide all messages from this source by right-click on the little arrow in front of the trace and select the option to hide all messages from this source.

For doing it in JavaScript, you could define your own console.trace. This workaround is suggested in another bug-report on the same subject from 2017 whose Status is "WontFix (Closed)" Issue 697203: console.trace() expands automatically resulting in console bloat :

if(window.console && console.trace) {
    var oldTrace = console.trace;
    console.trace = function(msg) {
        console.groupCollapsed(msg || 'trace');
        oldTrace.apply(this);
        console.groupEnd();
    }
}
2
  • "so there is not much hope from Mozilla" Do you mean Google?
    – Black
    Commented Jul 5, 2023 at 9:45
  • 1
    @Black: Oups, corrected.
    – harrymc
    Commented Jul 5, 2023 at 11:10
1

The answer is here https://stackoverflow.com/questions/52595559/how-to-log-js-stack-trace-with-console-trace-but-keep-it-collapsed

console.groupCollapsed('name to show to identify trace');
console.log('additional data hidden inside collapsed group');
console.trace(); // hidden in collapsed group
console.groupEnd();
3
  • 1
    The trace is coming from in some JS library, so this solution would require me to override it, which would be possible I guess, however I wanted to know if it is possible to collapse trace log in browser by default, instead of changing the JS code.
    – kajacx
    Commented Sep 15, 2019 at 19:44
  • Maybe console.error would work for you then? Assuming that you don't want to ship this to production, and only want to see the traces temporarily. Granted, that filtering could become not very simple, but for that you can add a unique string to the start of your log, and filter that in or out. Commented Oct 9, 2020 at 18:45
  • This wouldn't work with trace logs from jquery migrate... there should be some overriding code config to add to our own scripts. maybe something like console.trace.autoExpand(false); Migrate just clutters the console with expanded traces
    – Studocwho
    Commented Apr 28, 2023 at 22:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .