Cotten
Cotten

Reputation: 9077

Shortcut to clear console in Chrome dev tools without having dev tools focused

When dev tools is focused, you can clear the console with the shortcut cmd + k. Is there a shortcut or a hack to clear the console while having focus on the web-page itself?

Background: I'm often using the mouse to click some buttons in the webpage and I'd like to clear the console using a shortcut with my left hand just before I click the button with the cursor (the right hand can't since it's holding the mouse)

Upvotes: 2

Views: 550

Answers (2)

Kayce Basques
Kayce Basques

Reputation: 25917

Here's a hack. This only works on Chrome 61 and later. 61 is currently in Beta. It should hit Stable by mid-September 2017. Check chrome://version to see what version you're running.

  1. Press Control+` (that's the backtick character, to the left of the 1 key on QWERTY keyboards). If you've got the Console panel open, focus goes back to that. If you're on a different panel, focus goes to the Console drawer. If the drawer is closed, DevTools opens it first and then puts focus in it.
  2. Press Control+L (Mac, Windows, Linux) to clear the Console.

Upvotes: 0

Matt Zeunert
Matt Zeunert

Reputation: 16561

You can add a handler to the page that calls the console.clear method when a shortcut is used.

document.body.onkeydown = function(){
    console.clear()
}

This will clear the console when any key is pressed, but you can easily add an if statement that checks that the key that was pressed matches the shortcut you want to use.

Upvotes: 2

Related Questions