24

In bash, I use the history-search-forward and history-search-backward feature to allow me to type in a few characters of the command I want to run, then press up arrow to cycle through items in my history that match those characters.

I want the same thing for the chrome devtool console. I often use up arrow to cycle through my history, but there doesn't seem to be a way to filter it. Does anybody have a clever solution?

[Just a note that command history matching has improved a lot in recent versions of Chrome. It's not exactly how I would like it, but it's pretty good.]

Mike McKay
  • 2,388
  • 1
  • 29
  • 32

4 Answers4

17

Try this: (based on How to remove all recent console command)

  1. Open Chrome Dev Tools on the Chrome Dev Tools window (as per post above) by following steps 1-3 on the first answer (by Rob W). Don't do step 4 or you'll wipe out your history!
  2. Run this command in the new Dev Tools console: JSON.parse(localStorage.getItem('consoleHistory')).filter(function(item){ return ~item.indexOf('indexedDB');})
    • Replace "indexedDB" with whatever it is you want to filter on.

TL;DR

  • Chrome Dev Tools is technically just another browser window.
  • The LocalStorage of the original Dev Tools is for the site you are browsing.
  • By opening Dev Tools on the Dev Tools, gives you the LocalStorage for the Dev Tools window and thus gives you access to the consoleHistory.
  • localStorage.getItem('consoleHistory') gives you a string of an Array, so you need to parse it (i.e. JSON.parse()) back into an Array so you can filter it.
  • The ~ in front of ~item.indexOf('indexedDB') is a bitwise shortcut for item.indexOf('indexedDB') > 0
Bob
  • 181
  • 1
  • 6
  • Clever hack! And while it does allow you to search your command history, you can't use any found command because this new console is targeting the original console, not the original browser page. If you really need to find an old command this is one way to do it, but not a quick filtering shortcut. – Mike McKay Nov 16 '17 at 08:18
16

Reverse search feature is not there in Chrome developer tools. I have logged a request for the reverse search feature. Please star the same.

http://code.google.com/p/chromium/issues/detail?id=171386

I use Snippets (Chrome Developer Tools: What is Snippets Support?) for keeping track of all my commands.

Community
  • 1
  • 1
Varunkumar Nagarajan
  • 1,807
  • 1
  • 24
  • 43
  • 4
    The support for history autocomplete has been added about a year back -- https://bugs.chromium.org/p/chromium/issues/detail?id=171386 Though it is not exactly the same, it is very much handy to look at console history. – Varunkumar Nagarajan Sep 05 '17 at 14:36
2

Adding my 2 cents since the most upvoted answer has stopped working.

Chrome does not have a bash-like search yet (Ctrl + R) but recent versions of Chrome have history autocomplete. Start typing a command and it will show suggestions from the history (just below the usual syntax suggestions). This is not exactly "search", but good enough for "starts with" type of filtering.

Works in all Chromium browsers including MS Edge

enter image description here

Alex from Jitbit
  • 53,710
  • 19
  • 160
  • 149
-1

When you open the console of the devTools and clicking on the up-arrow (or the down-arrow) you will start cycle through your 'history' of commands.

Ido Green
  • 2,795
  • 1
  • 17
  • 26
  • 3
    Yes, but I want to filter that result based on whatever characters I have started typing. – Mike McKay Aug 09 '12 at 16:07
  • 1
    Any luck tracking this down? I'd like to know where the history is stored so I can copy & paste collections of commands into a new editor – Alvin Jan 18 '13 at 20:50
  • 2
    @Alvin In case you're still searching: Here's a description how to access the console history: http://stackoverflow.com/a/21149275/726097 All these DevTool settings are, in the end, saved on disk; for OS X you can find them here: `/Users/john/Library/Application Support/Google/Chrome/Default/Local Storage` And I guess it is something similar on other systems. – einjohn Aug 23 '16 at 23:04