View or Reset All Your Firefox Zoom Settings (Shallow Thoughts)

Akkana's Musings on Open Source Computing and Technology, Science, and Nature.

Sat, 29 Jan 2022

View or Reset All Your Firefox Zoom Settings

Firefox's zoom settings are useful. You can zoom in on a page with Ctrl-+ (actually Ctrl-+ on a US-English keyboard), or out with Ctrl--.

Useful, that is, until you start noticing that lots of pages you visit have weirdly large or small font sizes, and it turns out that Firefox is remembering a Zoom setting you used on that site half a year ago on a different monitor.

Whenever you zoom, Firefox remembers that site, and uses that zoom setting any time you go to that site forevermore (unless you zoom back out).

Now that I'm using the same laptop in different modes — sometimes plugged into a monitor, sometimes using its own screen — that has become a problem.

When I zoom in Firefox, sometimes it's because a site has tiny text. (Or because it has huge text: newspaper sites seem to think they need to display everything big enough that you can read it from across the room. But Reader Mode takes care of that, at least after I've customized it a bit to make the font size and page width sane).

But a lot more often, it's because text that looked fine on the big monitor is too small on the laptop screen. Just because I want to zoom right now< doesn't mean I want every page on the site to be that size forever. Even aside from not wanting my settings cluttered by hundreds of sites I've only viewed once and may never visit again.

(Ironically, one place where I often do want zoom remembered is on specific PDF documents; but PDF is one place that Firefox doesn't remember zoom levels, natch.)

Recently, I was exploring Firefox settings and happened across the place where the zoom settings are stored. Like nearly everything in Firefox these days, they're in an sqlite3 file, content-prefs.sqlite inside your Firefox profile.

Viewing Zoom Settings

You can view the contents of this file from the sqlite3 command line, with one caveat: sqlite3 won't let you open the file if Firefox already has it locked. To get around that, if you just want to read it, make a copy of the file and run sqlite3 on the copy. (In theory, you're supposed to be able to open files read-only even if they're locked by using a URI: sqlite3 "file:///home/yourname/.mozilla/firefox/profilename/content-prefs.sqlite?mode=ro". In practice, as soon as you try to query anything you'll get Error: in prepare, database is locked (5).)

Examining the zoom settings is a bit baroque. There's a table called settings, and another one called prefs. settings gives you the IDs for various properties you can look up, one of which is browser.content.full-zoom:

sqlite> select id,name from settings where name like '%zoom%';
2|browser.content.full-zoom
So on my system, the full-zoom ID is 2.

Next, get the prefs corresponding to that setting ID:

sqlite> select id,groupID,value from prefs where settingID is 2;
3|3|1.1
4|4|1.33
13|13|1.1
16|16|1.2
17|17|1.2
18|18|1.1
20|20|1

These are all the zoom settings stored in my browser right now: only a few because I deleted most of the rest already. The value (the last field) in each case is the magnification setting, which might be 1.1, 1.33 or whatever.

Which sites correspond to each zoom level? Note the groupID (the second number) from each of those prefs lines. The groupIDs correspond to ID in the groups table, so:

sqlite> select name from groups where id is 18;
forums.debian.net

You can also delete all zoom settings, with

sqlite> delete from prefs where settingID is 2;
replacing 2 with that zoomID you found earlier. Of course, you can't do this if you opened the file as a URL in read-only mode; you have to quit Firefox and open the file in read-write mode.

Scripting in Python, and a Documentation Error

With this info, it's easy to write a Python script to view the current zoom settings or clear them all, which of course I did: firefox-zoom.py.

The only tricky part was opening the file read-only. The Python sqlite3 documentation claims that you can use sqlite3.connect('file:path/to/database?mode=ro', uri=True) but it's not true: using the same URI that works from the sqlite3 commandline fails in Python with a sqlite3.OperationalError: database is locked.

Fortunately someone on the #python IRC channel suggested adding immutable: file:/home/yourname/.mozilla/firefox/profilename/content-prefs.sqlite?immutable=1&mode=ro" Though immutable isn't documented anywhere in the Python sqlite3 documentation (it is mentioned in the sqlite documentation), that enabled my Python script to open the file read-only while Firefox is running.

Tags: , , ,
[ 18:04 Jan 29, 2022    More tech/web | permalink to this entry | ]

Comments via Disqus:

blog comments powered by Disqus