Writing directly to cookies.sqlite

I have an extension (FEBE) that, among other things, backs up and restores cookies. I backup the cookies by opening cookies.sqlite, read each record and write a JSON string to an output file. When restoring, I do just the opposite - read a JSON string from the output file and write it to cookies.sqlite. Fx would recognized the restored cookies immediately.

This all has been working fine until recently (probably when Fx 44.0 was released). Now, the cookies are successfully written to cookies.sqlite (I can open the database and see them all there) but they do not show in Fx options > Privacy > Show Cookies.

It is acting like the currently recognized cookies are in a cache somewhere. Can anyone tell me where this cache might be? Or is there a way to tell Fx to re-examine cookies.sqlite and update this cache?

Cookies have always been stored internally in a hash table and only read from the database at startup. I’m not sure how your addon was working before. There have been minor changes recently (in 42, I think) to reduce the number of times Firefox writes to the database for multiple rapid cookie changes, but I don’t see how this would affect anything.

You don’t have access to the cookie cache, at least not from javascript. Your best bet might be to find out how on earth this was working before, and find a way to trigger that in the latest versions.

Maybe there were changes related to multiprocess. I haven’t looked into how cookie changes are synchronised between chrome and content. Chrome obviously needs some way to see the same set of cookies as the content process and this might be affecting you.

The cookies.sqlite schema changed in Firefox 44. Are you creating an invalid table, which would then be dumped by Firefox as corrupt?

You’re right … thanks.

The schema is different now. I was using a ‘CREATE TABLE’ command with a hard-coded statement. I’m changing the code to save a ‘CREATE TABLE’ command before I drop the existing table (that’s how I empty the database).

In case anyone else runs into this or a similar issue, here’s a snippet of how I grab the current table schema:

    stmt = "SELECT 'moz_cookies', sql from sqlite_master WHERE type = 'table'"
    result = DB.createStatement(stmt);
    result.executeAsync({
        handleResult: function(aResultSet){
            let row = aResultSet.getNextRow();
            createStatement = row.getResultByName("sql");
            result = DB.createStatement(createStatement);
            result.executeAsync({ ...

`

Could you share the code…how do we do this for Chrome Cookie…My intention is to read the existing cookie DB schema and the insert the data into Cookie…I need to do it in C#

Do you mean Google Chrome? You’ll probably have better luck asking elsewhere.