How can I delete all web history that matches a specific query in Google Chrome

That’s simple & easy.

Search for what you want to remove. Select the first one. Now scroll to the latest result. Press shift & choose the latest one. Now all matches are selected and you can remove them together.


In some cases, removing an address from history results is not enough for stoping that address from appearing in url bar auto suggestions.

In that case visit here : https://superuser.com/a/273280/121184


Update Jan 2019

Now Chrome supports the keyboard shortcut CtrlA or A


Original answer

You can take the hacker shortcut injecting JavaScript code.

Step 1 Since Chrome history is queried inside a iFrame, we have to visit: chrome://history-frame/ (copy and paste URL)

Step 2 Do the search query.

Step 3 Open the Chrome console(F12 or CtrlShifti or i) and execute:

var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; ++i) {
  if (inputs[i].type == "checkbox"){
    inputs[i].checked = true;
  }
}
document.getElementById("remove-selected").disabled = false

Step 4 Hit the 'Remove selected items' button.

Actually this deletes the elements in the current page. I might try to extend it, but it's a good starting point. Read the full article in my blog.


For literal values of "query"...

You can even query your Chrome history using SQL. (Firefox too: see below. Of course, the appropriate file path will have to be changed).

First of all, you need to locate the Chrome History file. This is, on my system, in

C:\Documents and Settings\Leonardo Serni\Impostazioni locali\Dati applicazioni\Google\Chrome\User Data\Default

which ought to translate in a more general

<USER FOLDER>\Local Settings\Application Data\Google\Chrome\User Data\Default

In there, you will find a "History" file. It is a SQLite3 file, and to manipulate it, Chrome has to be closed. If you make a mess of it, delete the History file and start anew - it's just as if you had cleared the whole Chrome history.

Then, rename the file to History.sqlite3 and install SQLiteMan (or any other SQLite3 editor - in Windows, double-clicking on the file might be enough to trigger a suggestion), then open the file (n.b. some utilities might not need the renaming thing. Maybe try without renaming first, to save work).

In the URLS table, you will find the URLs you have visited. For example I can run the query:

SELECT * FROM urls WHERE url LIKE '%meetup%';

to view all occurrences of 'meetup' in either the host or pathname part of the URLs I visited. Or I could search for pr0n, or... anything at all, as long as I adhere to SQL syntax.

You can even use the other information to run the query, for example the time of last visit. Only remember that you need to convert the dates to Chrome time, which is the number of microseconds elapsed from January 1st, year of our Lord 1601. On a Unix box, typing date +%s will tell you the number of seconds; multiply by one million, add 11644473600 and you're done.

For example, select visits after October 1st, 2013:

SELECT * FROM urls WHERE ((last_visit_time/1000000)-11644473600) - 
    strftime('%s', '2013-10-01 00:00:00') > 0;

To delete, just replace SELECT * with DELETE and press F9 to execute the query.

You can use NOW() instead of the current date, and any other SQLite syntax.

(In case, the "Archive History" file holds the last history archived by Chrome).

When you're done, if needed, rename back the file to "History".

Automating it: one-click sanitization

You need a command-line SQLite utility such as sqlite3 or sql3tool. Then you write a script or batch file, modifying the code below with the appropriate paths (you don't want to clear my history leaving yours untouched, do you?):

# ENSURE CHROME IS CLOSED (pskill by SysInternals might be useful)
echo "DELETE * FROM urls WHERE url LIKE '%facebook%' OR url LIKE '%twitter%';" | sql3tool "C:\Documents and Settings\Leonardo Serni\Impostazioni locali\Dati applicazioni\Google\Chrome\User Data\Default\History"
echo "DELETE * FROM urls WHERE url LIKE '%porn%' OR url LIKE '%my-employer-is-a-moron%';" | sql3tool "C:\Documents and Settings\Leonardo Serni\Impostazioni locali\Dati applicazioni\Google\Chrome\User Data\Default\History"
echo "DELETE * FROM urls WHERE url LIKE ..."

Only remember that this erases your history on your instance of Chrome. If, for example, you use a proxy, and that proxy keeps logs, all those URLs will be still available in the logs.

UPDATE: Also, if you're using some brain-dead SQL tool that requires the file to have an explicit and known extension, you will have to perform an appropriate RENAME before starting operations, and another to put things back in order when you've finished:

REN "C:\Documents and Settings\Leonardo Serni\Impostazioni locali\Dati applicazioni\Google\Chrome\User Data\Default\History" "C:\Documents and Settings\Leonardo Serni\Impostazioni locali\Dati applicazioni\Google\Chrome\User Data\Default\History.sqlite3"
echo "DELETE * FROM urls WHERE url LIKE '%facebook%' OR url LIKE '%twitter%';" | sql3tool "C:\Documents and Settings\Leonardo Serni\Impostazioni locali\Dati applicazioni\Google\Chrome\User Data\Default\History.sqlite3"
REN "C:\Documents and Settings\Leonardo Serni\Impostazioni locali\Dati applicazioni\Google\Chrome\User Data\Default\History.sqlite3" "C:\Documents and Settings\Leonardo Serni\Impostazioni locali\Dati applicazioni\Google\Chrome\User Data\Default\History"

Anyway, once this is done, doubleclick on the script icon and hey presto!, your Chrome history is sanitized. It works with Firefox too; its timestamps might be in some other time reference frame, though (possibly plain Unix), so check the water before jumping in.

How about cleaning cookies?

You might want to do the same thing to cookies instead of History.

But you'll have noticed, in the Chrome data directory, other files than History, one of which is named Cookies... :-)

Advanced track covering

The SQL trick above is not limited to deletions. You can modify entries with the UPDATE command; and after deleting unneeded entries, you can use INSERT with the appropriate time and date macros to have Chrome believe that you visited some URLs you did not actually visit, or did not visit at some time and date.

This may come in handy in those cases when sanitizing a browser session would result in an unlikely picture of someone staring glazedly at an empty browser window for a very long time, and some kind of idle navigation is preferable. Of course, this assumes that no one notices that each day there is exactly the same navigation 'template'.