[Tutor] Advice on working with Firefox's cookies.sqlite

Jim jf_byrnes at comcast.net
Sat Jun 27 12:44:09 EDT 2020


I am writing a script that will delete unwanted cookies from the Firefox 
cookies.sqlite file  based on a white list. I found that I could not 
connect to the file in my profile directory when Firefox is active. If I 
copy cookies.sqlite to a temporary location the script will connect to 
the db and delete unwanted cookies.

The problem is when I copy the file back to my profile directory and use 
preferences to check for cookies, the deleted cookies have reappeared. 
This seems to be the result of a file called cookies.sqlite-wal in the 
same directory.

More info on sqlite-wal here: https://sqlite.org/wal.html

Based on what I read in the above link and some googling it looked like 
the cookies.sqlite-wal file had not yet updated the cookies.sqlite file.
So I copied the cookies.sqlite file and looked at it with a db viewer 
and the cookies I wanted to delete were not there. So I copied the 
cookies.sqlite-wal file to the same location and then ran this portion 
of the script and the cookies appeared in the db.

def sqlite3Connect():
     ''' Connect to cookies database '''
     conn = sqlite3.connect(WORK_AREA + "cookies.sqlite")
     conn.execute('PRAGMA wal_checkpoint(TRUNCATE)')
     return conn

Checking the db the cookies I wanted to delete were now in the db. I 
then ran the part of the script that deleted the cookies. After running 
the db viewer I could see the cookies had been deleted. However when I 
deleted the cookies.sqlite and cookes.sqlite-wal files from my firefox 
profile and copied my updated cookies.sqlite file to my profile, 
checking with firefox still showed the cookies I tried to delete.

At this point I am out of ideas and wondering if anyone knows how to 
successfully manipulate this file?

Thanks,  Jim



More information about the Tutor mailing list