15

Is there anyway that I can save or export the history of JavaScript console input (console history) in Google Chrome? I'm not looking to save the output or the errors, so hovering my mouse over the console box, right-clicking, and selecting Save as... is not the solution. I don't want to have to scroll up with the arrow keys and copy-and-paste the contents each time.

Salman A
  • 262,204
  • 82
  • 430
  • 521
Melab
  • 2,594
  • 7
  • 30
  • 51
  • Possible duplicate of [Capturing javascript console.log?](https://stackoverflow.com/questions/11403107/capturing-javascript-console-log) – Hyyan Abo Fakher Aug 11 '18 at 18:34
  • 17
    You really ought to [**accept**](https://meta.stackexchange.com/q/5234/234215) some of the fine answers you've received to the [94 questions you've asked](https://stackoverflow.com/users/1953537/melab?tab=questions). **Asking 94 questions and accepting 0 of the fine answers you've received** (and only ever upvoting twice in 5 years) shows a lack of appreciation for the help you've received and failure to help future readers. It's not too late to fix this situation. You should do so now, starting with @SalmanA's answer here. – kjhughes Aug 12 '18 at 18:00

2 Answers2

48

I figured out a weird solution that seems to work:

  • Open Chrome Developer Tools (press CTRL + SHIFT + J)

  • If the developer tools window is docked, undock into a separate window (open the menu to choose docking option)

  • Inside the developer tools window, press CTRL + SHIFT + J which will open a developer tools window for the developer tools window!

  • Inside the second developer tools window, enter the following command inside console:
    localStorage.getItem("consoleHistory")

This should print the console history, encoded as JSON inside the console. You can decode the JSON into an array using this command:

JSON.parse(localStorage.getItem("consoleHistory"))

Or copy the JSON to clipboard using:

copy(localStorage.getItem("consoleHistory"))
Salman A
  • 262,204
  • 82
  • 430
  • 521
  • 6
    Great workaround, but tedious. I fiddled around and found a way which does not require undocking and has less steps. Create a bookmark to `devtools://devtools/bundled/devtools_app.html` for easy access (or paste it in a new tab). Whenever you want to get the history, go to that page, open the console _(DON'T use the one already displayed)_, and paste `copy(JSON.parse(localStorage.getItem("consoleHistory")).join('\n'))` – blex Jun 21 '20 at 00:17
0

consoleHistory in localStorage keeps only the most recent 300 records, and older records appear to have been deleted.

hrdom
  • 83
  • 1
  • 7