Skip to content

Instantly share code, notes, and snippets.

Last active April 2, 2024 20:18
Show Gist options
  • Save paulirish/c307a5a585ddbcc17242 to your computer and use it in GitHub Desktop.
Save paulirish/c307a5a585ddbcc17242 to your computer and use it in GitHub Desktop.
resolving the proper location and line number through a console.log wrapper

console.log wrap resolving for your wrapped console logs

I've heard this before:

What I really get frustrated by is that I cannot wrap console.* and preserve line numbers

We enabled this in Chrome DevTools via blackboxing a bit ago.

If you blackbox the script file the contains the console log wrapper, the script location shown in the console will be corrected to the original source file and line number. Click, and the full source is looking longingly into your eyes.

You can try it out here:

Blackbox the source file:


You can right-click the file in the editor, as well. Or blackbox via regex in Settings.

Logs will be resolved back to their call frame.


FWIW, Blackboxing does a lot. Blackboxing a file means:

  • Exceptions thrown from library code will not pause (if Pause on exceptions is enabled),
  • Stepping into/out/over bypasses the library code,
  • Event listener breakpoints don't break in library code,
  • The debugger will not pause on any breakpoints set in library code.

Read more about it over at

Cheers and thanks crbug/249575

Copy link

Awesome, this is just what I've been looking for.

Copy link


Copy link

thany commented Feb 28, 2015

Can it be done in Firebug?

Copy link

wixo commented Feb 28, 2015

Nice! no more Error throwing :)

Copy link

@wixo: check out .. it preserves original line number without throwing an exception.

Copy link

Very nice and I was hoping to see some way to automatically whitelist the blackboxed URLs - the regex list didn't disappoint.

Suggestion for further improving it: Standardise the whitelist into a manifest.json equivalent (dev.json or something) so the default setting can be part of the project instead of (or in addition to) the browser settings. It would be a hassle for every developer of a project to have to configure the same whitelist manually after checkout and whenever it needs to change.

Copy link

patik commented Feb 28, 2015

@wixo also supports line numbers: and logs in legacy browsers (but no line numbers there)

Copy link

derblub commented Feb 28, 2015


Copy link

msafi commented Feb 28, 2015

That's great! Thanks so much! Is it also possible to filter out 3rd party libraries from the stack trace by blackboxing? :D

Copy link

jlukic commented Feb 28, 2015

Semantic UI uses a slightly different implementation for wrapping console calls that preserves line numbers and doesn't require blackboxing.

module.debug = function() {
  if(settings.debug) {
    // overwrite self
    module.debug =, console, + ':');
    module.debug.apply(console, arguments);

We also use a console.table to do grouped performance logging, console.groupCollapsed is epic.

log gif

Copy link


Copy link

IRus commented Aug 5, 2015

Any tips for Firefox users?

Copy link

here's the FF bug about implementing this

Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment