console.trace() expands automatically resulting in console bloat
Reported by
je...@trybaker.com,
Feb 28 2017
|
||||
Issue descriptionUserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36 Steps to reproduce the problem: 1. add console.trace() to any method in your javascript 2. view console and see it is already expanded What is the expected behavior? To print the console.trace with a caret for expanding What went wrong? it auto expands Did this work before? N/A Chrome version: 56.0.2924.87 Channel: stable OS Version: OS X 10.11.6 Flash Version: Shockwave Flash 24.0 r0 Was this an intended feature update? It's quite frustrating to work with.
,
Feb 28 2017
Thank you for the workaround in the meantime.
,
Mar 1 2017
jesse@ Thanks for the issue. Could you please provide us any sample test file or URL to triage the issue from test team end. Thanks,
,
Mar 1 2017
kavvaru@, open devtools and run "console.trace()" without quotes in the console: the output is expanded (there is a triangle button to toggle the state). This becomes a nuisance when each trace contains 10-50 rows (typical case for the modern javascript frameworks) and there are many traces shown.
,
Mar 1 2017
The point of console.trace is that it spams you with the trace. You could use console.warn() that also captures the trace, but does not expand it by default. Would that work?
,
Mar 2 2017
Why is the point of it to spam you? warn will work though. Thank you for the suggestion.
,
Mar 2 2017
if(window.console && console.trace) {
var oldTrace = console.trace;
console.trace = function(msg) {
console.groupCollapsed(msg || 'trace');
oldTrace.apply(this);
console.groupEnd();
}
}
Here's a slightly better polyfill for anyone else who wants to still use console.trace();
,
Mar 2 2017
Marking as won't fix due to viable workaround.
,
Apr 13 2018
Workaround above always outputs bold text and doesn't support css.
Here's a slightly better slightly better polyfil:
if(window.console && console.trace) {
var oldTrace = console.trace;
console.trace = function(msg, css) {
msg = msg && String(msg) || 'trace';
if (!msg.startsWith('%c')) {
msg = '%c' + msg;
css = 'font-weight: normal;';
} else {
css = 'font-weight: normal; ' + String(css || '');
}
console.groupCollapsed(msg, css);
oldTrace.apply(this);
console.groupEnd();
}
}
Testing it with:
console.trace('testest');
console.trace('%ctestest', 'color: #F00');
console.trace('%ctestest', 'color: #F00; font-weight: bold;');
console.trace(new RegExp(), new RegExp());
works as expected.
|
||||
►
Sign in to add a comment |
||||
Comment 1 by woxxom@gmail.com
, Feb 28 2017Use console.groupCollapsed [1]: function trace(msg) { console.groupCollapsed(msg || 'trace'); console.trace(); console.groupEnd(); } On the other hand, it might be nice if console.trace accepted a second boolean parameter to control the initial state: console.trace(object, showCollapsed) [1]: https://developers.google.com/web/tools/chrome-devtools/console/console-reference#consolegroupcollapsedobject_object