Skip to content

Instantly share code, notes, and snippets.

@grok
Last active August 27, 2022 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save grok/4b79c0020469f5fae27f3445b022926e to your computer and use it in GitHub Desktop.
Save grok/4b79c0020469f5fae27f3445b022926e to your computer and use it in GitHub Desktop.
Chrome DevTools / console.log Expand All / Collapse All

Hacking Chrome DevTools

You ever have a bunch of console.log instances you wish you could just expand or collapse at once? Well this will do that.

You of course need to open your DevTools Console, on a mac that shortcut is ⌘ (Command) + ⌥ (Shift) + J

Now hit ⌘ (Command) + ⌥ (Shift) + J again to open DevTools for your DevTools.

Then run the code below. If you run it once, it will collapse everything it can. If you run it again, it will expand.

Before (Default DevTools Output):

image

After (Running the Script Below): image

Result: image

// Alias of document.querySelectorAll() is $$
// We want just the top level of messages. We don't want to click on their children.
$$('.console-group-messages > .console-message-wrapper').forEach(e => {
let element = getEventListeners(e);
// If we have a click eventListener.
if (typeof element.click == 'object') {
// Click on the thing to collapse or expand.
element.click[0].listener(true);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment