The site uses cookies that you may not want. Continued use means acceptance. For more information see our privacy policy.

Selectively Cleaning Firefox History

Small script for removing some items from Firefox history.

Firefox does a nice job of keeping my history. But not a perfect one: certain history gets in my way, and I didn’t find a good extension to automatically clean it. So I wrote a python3 script that lets me do it manually.

GitHub: Gist: Python 3 script to manually remove some Firefox history items.


# The queries operate only if either:
#  * There are more than 10 visits (for things like my mail, which only bug me
#    once they are trying to clog up my new tab page)
#  * They are > 10 days old (for things like searches; recent searches aren't
#    a big problem; old searches are).

# This should be run only if Firefox is shut down (and I mean really; you
# don't want to corrupt your DB because it was hung!)

# Also, take care about your queries!

import datetime
import sqlite3
import time

PLACES_DB = "/EDITME/path/to/places.sqlite"

conn = sqlite3.connect(PLACES_DB)

cursor = conn.cursor()

select_statement = """select url from moz_places
                      where url like :query and
                      (last_visit_date < :ten_days_ago or
                       visit_count > 10)"""

delete_statement = """delete from moz_places
                      where url like :query and
                      (last_visit_date < :ten_days_ago or
                       visit_count > 10)"""

# The time stored in the DB is in UTC, so we need to be consistent.
old_time_dt = datetime.datetime.utcnow() - datetime.timedelta(days=10)
raw_time = time.mktime(old_time_dt.timetuple())
ten_days_ago = int(raw_time * 1000000)

queries = ["%localhost/roundcube/?%", # Round Cube
           "", # Google Search

# Set to True if you want to preview what would be deleted

    statement = select_statement
    statement = delete_statement

for query in queries:
    variable_bindings = {"query": query, "ten_days_ago": ten_days_ago}
    cursor.execute(statement, variable_bindings)
    if TEST_MODE:
        for row in cursor:

if not TEST_MODE:
    print("Deleted {} rows.".format(conn.total_changes))


To use it you first shut down Firefox. You should make sure it’s really shut down, as you don’t want to try to modify the database while something else is. If you want to be extra paranoid, make a fresh backup your places.sqlite file.

You need to edit the PLACES_DB variable to point to your places.sqlite file. It’s usually somewhere like: /home/YOUR_USER/.mozilla/firefox/YOUR_PROFILE_FOLDER/places.sqlite.

You need to edit your query strings (queries variable). Use % as a wildcard match.

You should set TEST_MODE to True and run the script once to make sure it’s hitting your targets. The two statements are the same except one is a SELECT and the other a DELETE.

TEST_MODE will simply print what the script would delete.

If you’re satisfied, you can turn TEST_MODE off and let it rip.

If you’re adventurous you can install the sqlite3 command line tool and open the database and explore. Note that you should also ensure Firefox is not running (at least not on the same profile) when opening your places.sqlite in sqlite3.

Looking Forward to the Future of Iceweasel

Just a short look at some of the things I’m looking forward to seeing in the future versions of Firefox/Iceweasel.

Mozilla Persona

The biggest feature that I really hope takes off will be Mozilla Persona, which is will bring the ability to replace all the Login with Facebook and OpenID and remembering a million passwords with a system that allows you to have multiple managed identities with your choice of identity provider.

In many ways BrowserID is an evolution from OpenID, but as it gets built-in to the browser, it should bring an easier adoption curve with it. This can’t happen soon enough, with more and more major sites being cracked and the user data being strewn across the web.


The visual refresh of the browser (see mockups: Mozilla: shorlander: Australis Design Specs for Linux) is going to be great. My favorite part of this is the non-active tabs having low-volume to their appearance. This gives a much nicer feel and the impression that they are truly in the background; your active tab is what everything below it is about.

That will be improved over time as other features of the browser enhance that contextual choice.

GCLI — the Graphics Command Line

This is a developer tool, which allows you to easily access developer tools and commands so that you can try things out while developing on the web platform. It should allow for things like color manipulation, screenshot creation (great for documentation), and other tasks. Documentation at MDN: Tools: GCLI, which leads me to the final thing about Mozilla I’m really looking forward to:

MDN Kuma Switch

This isn’t really in the browser itself, but it’s just as important: the Mozilla Developer Network (MDN) is moving to a different platform, which will allow it to boldly go where no wiki has gone before. I use MDN a lot for learning about the browser and the web, and I’ve even made some minor edits to it before. But the current (soon-to-be-old) platform has what I consider a clunky interface for editing articles, and it’s likely it’s deterred some people from contributing.

The new MDN is based on the same codebase as the awesome Mozilla Support (SUMO), which means that further progress can be shared between both sites.

Really, some great work is afoot. I look forward to seeing what’s next.

Fixing Broken Things

Some thoughts about how to fix things that are broken.

For me, the Things in the title refers mostly to software, but it could be anything. Today there are two broken things, one which I’ve already fixed.

The first thing that was broken was this blog. I’m not sure how long the problem lasted, but if you attempted to access it sometime between just a bit ago and whenever it broke, it didn’t work. You would’ve gotten an error.

My method of fixing it was roughly:

  1. Notice it’s broken.
  2. Confirm it’s actually broken (eg, that it wasn’t a connection problem or browser-related problem).
  3. See how broken it is.
  4. Fix it.

The first step came for free, as it usually does, except when things break in very subtle/spooky ways. This actually ties in with the third step as much as the second step.

The second step entailed opening the site in a different browser and trying a few other things like making a request with curl -I <domain>. Again, this also ties in with step three.

The third step was getting on the server itself and really finding the root of the problem. In this case, the problem was that the version of PHP the server runs changed, making something that was probably a warning before into a full error.

The fix wasn’t hard once I had that direct, small, known problem.

But the key point here is that the first three steps and step four are basically two steps, and that they’re both essentially the same process.

Part one is getting the problem understood, modeled. Part two is getting a solution understood, modeled.

Both are scientific in their best case: forming a hypothesis, testing it, and observing the results.

Either can block. Sometimes you can’t find the problem, and sometimes a solution is elusive. Sometimes to find the problem would require access or tools that aren’t available. Same for finding or implementing a solution.

The other problem giving me a rash today is my Firefox profile. This profile has been with me for a long time. It’s from at least 2005, as it came with me when I switched to GNU/Linux in 2006. It’s only recently had some problems:

  1. A particular website which I don’t frequent causes a complete and utterly bad situation: it eats all my memory and then starts eating my swap.
  2. Firebug just won’t work.

For reference, I’ve got six gibibytes of RAM, which never get filled. Within a minute of visiting the website in question, swap begins to be flooded, my RAM being completely filled.

In both cases, using a different profile fixes the problem, but even in safe mode on this profile the problem persists (can’t check Firebug from safe mode, but some console errors reinforce the fact that it wouldn’t work there).

The question is whether it’s worth it to try to track down the problem with the profile. It’s probably not. Recently Firefox introduced a feature (available in Firefox 13, currently beta) that will reset my profile, but it’s currently disabled for me in Iceweasel. That’s seems to be due to Iceweasel being dependent upon XUL runner on Debian, in order to not install the same support libraries for all Mozilla applications.

Using the web console, one can see that the following migrators are available:

  • browser/chrome
  • browser/firefox
  • browser/ie
  • browser/safari

While I could force the issue, without knowing what would happen, this would be risky. An alternative would be to create a new profile, throw some data in, and try it there first, to see if it’s safe.

There are other ways to achieve the equivalent of a reset, the most useful being to use the Firefox Sync service to store the data, then attach a new profile to Sync and let it handle the rest.

If I decide to go for a new profile, this will fit the bill nicely. But it remains to be seen if I can still figure out what the problem with this profile is.

And here’s where we depart. Next week, I’ll leave a note about the outcome. I’ll probably replace the profile either way, but it would be neat to know what the problem is.