17

I often use Chrome's debugger console for experimenting with javascript code fragments. When I got it right I usually want to copy the needed commands into my script, but here is where it gets messy. The is no filter options for commands and no way to call certain commands back (like with Ctrl-R in Bash) so you need to step through all the commands in the history and copy the commands you want one by one.

Instead, I think it should be possible to retrieve the command history from some file or Sqlite database. But I can't find it.

So my question is: Where is Chrome's debugger console command history stored?

marlar
  • 3,858
  • 6
  • 37
  • 60

3 Answers3

16

I found an answer here: How to access firefox web console command history?

I had some trouble getting it working, but here is how I did.

Open the developer console (shift-ctrl-I). Then open that console in a new window if it isn't that already by using the menu in the upper right (the three dots).

When it is a separate window, press shift-ctrl-I again. Then paste something like this:

var hist = JSON.parse(localStorage.consoleHistory);
hist.forEach(function(command){
  console.log(command);
})

Now, with all the commands in the console you can either copy them all to the clipboard or use the filter field above the console to do some filtering on them (you can use regex).

marlar
  • 3,858
  • 6
  • 37
  • 60
  • For me, opening the developer console OF a windowed developer console via keyboard shortcut no longer worked as of `107.0.5304.62 (Official Build) (x86_64) Revision 1eec40d3a5764881c92085aaee66d25075c159aa-refs/branch-heads/5304@{#942}` on `macOS Version 12.6 (Build 21G115)`. However, I could still point my browser to devtools://devtools (which 200s a document that says "HTTP/1.1 404 Not Found" but critically actually loads something that devtools://arbitrary-example-string does not) and then perform this command from the developer console for that tab (windowed or otherwise). – merkworku Dec 01 '22 at 18:30
5

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

Seems there was talk of such a feature which never came to fruition You can collect some people and pressure the devs to put it in, or get it done. Sounds really useful to me (:

For retrieving history : https://developer.chrome.com/extensions/experimental_devtools_console#method-getMessages

How about developing an extension around that ?

DannyZB
  • 523
  • 2
  • 16
0

Adding To marlars answer :

Actually i think its a little useful to not convert it into json. you can just keep it as a string so that you can use .indexof('yoursearchvalue')

And you don't have to always type that piece of code. you can just go to the Application tab -> Local Storage -> Devtools Entry and click on the consoleHistory

akashmohan
  • 343
  • 3
  • 10
  • You are right, but it takes quite a few clicks. I have actually put my code in a snippet called "Console history". Then I just run that snippet. – marlar Nov 19 '19 at 11:22