How to filter chrome's devtool console history

偶尔善良 提交于 2020-01-22 10:34:06

问题


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.]


回答1:


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.




回答2:


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



回答3:


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.



来源:https://stackoverflow.com/questions/11672502/how-to-filter-chromes-devtool-console-history

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!