stoically / temporary-containers

Firefox Add-on that lets you open automatically managed disposable containers
https://addons.mozilla.org/firefox/addon/temporary-containers/
MIT License
853 stars 62 forks source link

Temporary containers not removed with new sync feature #371

Open neekt opened 4 years ago

neekt commented 4 years ago

I've just noticed that with Firefox's new Multi-Account Containers sync feature, temporary containers are being synced across browsers on different machines, and then not removed, even when all instances of the container (e.g., tmp4) are closed in both browsers. Completely closing both browsers and then re-opening doesn't get rid of them either. They can be manually removed, if you manually remove them from both browsers and then sync Firefox, but in my case I have found dozens of temporary containers are being synced and kept, so this is not practical.

I assume it's possible to deactivate the container syncing feature (it asks whether to activate it upon update to the new Multi-Account Containers version), but I actually find it quite useful. So if there is some way to prevent temporary containers from being synced (ideally), or (less ideally) to allow them to still be automatically removed even after they've synced, that would be great.

This is using Automatic Mode, deleting no longer needed temporary containers after the last tab in it closes, and reusing available numbers in settings. Everything else is set to default.

avian2 commented 2 years ago

@neekt You probably hit the storage quota on the sync server. See my comment about "HTTP 507 Insufficient Storage" error above.

I've heard that resetting your account password (as in, going through the "forgot password" flow) fixes that because that deletes everything stored server side. I have not tried that myself (yet), so I can't say from first hand if it works or not.

neekt commented 2 years ago

@avian2 I just reset my account password via forgot password, and containers still aren't syncing at all.

I'm not sure how storage quotas work on the server, but newly added bookmarks and extensions are still syncing.

Sync is enabled in the Firefox Multi-Account Containers extension on both machines I'm testing this on.

avian2 commented 2 years ago

I'm not sure how storage quotas work on the server, but newly added bookmarks and extensions are still syncing.

That is my experience as well. Only the multi-account containers add-on sync is affected by this problem.

If I leave the sync enabled in Multi-Account containers, every once in a while Firefox will still download something like 8000 tmpxxxx containers from the server (which makes Firefox UI seriously unresponsive). I then have to run @Vinni's console script to remove them. The deletion won't sync back to the server, so I tend to just leave sync disabled these days.

You can enter "about:sync-log" in the URL bar and search for "Insufficient Storage" in the files there to see if this is still the same error happening for you after you did the "forgot password" thing. The files are ordered by date, so find one that was created after you reset the password.

neekt commented 2 years ago

If I leave the sync enabled in Multi-Account containers, every once in a while Firefox will still download something like 8000 tmpxxxx containers from the server

I haven't had this happen simply by leaving it enabled, but I did try to disabling and re-enabling containers in the browser yesterday, after which over one thousand tmp containers were synced to my browser 🙄

I can only conclude that resetting the password doesn't delete container data, despite the warning on accounts.firefox.com about everything being removed from the server when you do this.

cyrossignol commented 2 years ago

Just ran into this today. @Vinnl's solution in https://github.com/stoically/temporary-containers/issues/371#issuecomment-617626349 helped, but my extension's sync was still bricked, and it kept pulling all of the dead tmp containers. I extended the code a bit to clean up the sync storage as well, and I had to run through the steps below for each Firefox profile/computer where I use the extension. Dumping the full process here for my future reference and hope it helps someone.

  1. Open a new tab and go to about:debugging#/runtime/this-firefox
  2. Click the "Inspect" button next to Firefox Multi-Account Containers (not Temporary Containers!)
  3. Click the "Console" tab
  4. Enter the following code and press enter (change the prefix variable if needed):
// Your temporary containers prefix:
// WARNING: this script removes any container with this prefix regardless of the origin!
const prefix = 'tmp';

// First, turn off sync to speed up the following steps. This is the same as the "Enable
// sync" checkbox in the Multi-Account Containers options page.
// IMPORTANT: leave this disabled until you finish fixing all of your Firefox profiles.
await browser.storage.local.set({ syncEnabled: false });

// Delete local containers that start with `prefix`:
const containers = await browser.contextualIdentities.query({});
await Promise.allSettled(containers.map(container => {
  if (container.name.startsWith(prefix)) {
    return browser.contextualIdentities.remove(container.cookieStoreId);
  }
}));

// Delete containers from Multi-Account Containers' sync storage that start with `prefix`:
const data = await browser.storage.sync.get();
const keys = Object.keys(data).filter(k => data[k].name && data[k].name.startsWith(prefix));
await browser.storage.sync.remove(keys);

// If your sync is already broken, you may need to delete the following too. This list
// is one reason why sync breaks. The extension tries to put every deleted container 
// ID here to notify your other profiles, and this can bump the sync storage over the 
// quota limit:
await browser.storage.sync.remove('deletedIdentityList');

After that, I did a manual sync for good measure (about:preferences#sync → Sync Now). Repeat the whole thing for each computer with synced temp containers. Subsequent Firefox instances may put temp containers back into your Firefox account sync storage when they start, but these appear to go away when finishing the steps on that profile. I did have to re-do an earlier profile after finishing another computer. The sync did eventually stabilize, and I can sync persistent containers normally again.

At this point, the container sync is still disabled from the code above. Unfortunately, I don't see a way to make sync reliable without something like @stoically's PR at https://github.com/mozilla/multi-account-containers/pull/2231. In the meantime, it seems as if I can run manual syncs when needed:

  1. Close/delete the temp containers
  2. Enable the Multi-Account Containers' sync option
  3. Force a Firefox account sync
  4. Disable the Multi-Account Containers' sync option again
vbatts commented 2 years ago

crosslinking https://github.com/mozilla/multi-account-containers/issues/2349 because I just opened it, then found this extensive issue already in progress

FlorianWendelborn commented 2 years ago

The related PR that allows excluding containers from sync via regex was just merged: https://github.com/mozilla/multi-account-containers/pull/2231#event-6868662571

So, hopefully, the next version of multi-account-containers will work flawlessly ❤️

derkallevombau commented 2 years ago

Just ran into this today. @Vinnl's solution in #371 (comment) helped, but my extension's sync was still bricked, and it kept pulling all of the dead tmp containers. I extended the code a bit to clean up the sync storage as well, and I had to run through the steps below for each Firefox profile/computer where I use the extension. Dumping the full process here for my future reference and hope it helps someone.

1. Open a new tab and go to `about:debugging#/runtime/this-firefox`

2. Click the "Inspect" button next to **Firefox Multi-Account Containers** (not Temporary Containers!)

3. Click the "Console" tab

4. Enter the following code and press enter (change the `prefix` variable if needed):
// Your temporary containers prefix:
// WARNING: this script removes any container with this prefix regardless of the origin!
const prefix = 'tmp';

// First, turn off sync to speed up the following steps. This is the same as the "Enable
// sync" checkbox in the Multi-Account Containers options page.
// IMPORTANT: leave this disabled until you finish fixing all of your Firefox profiles.
await browser.storage.local.set({ syncEnabled: false });

// Delete local containers that start with `prefix`:
const containers = await browser.contextualIdentities.query({});
await Promise.allSettled(containers.map(container => {
  if (container.name.startsWith(prefix)) {
    return browser.contextualIdentities.remove(container.cookieStoreId);
  }
}));

// Delete containers from Multi-Account Containers' sync storage that start with `prefix`:
const data = await browser.storage.sync.get();
const keys = Object.keys(data).filter(k => data[k].name && data[k].name.startsWith(prefix));
await browser.storage.sync.remove(keys);

// If your sync is already broken, you may need to delete the following too. This list
// is one reason why sync breaks. The extension tries to put every deleted container 
// ID here to notify your other profiles, and this can bump the sync storage over the 
// quota limit:
await browser.storage.sync.remove('deletedIdentityList');

After that, I did a manual sync for good measure (about:preferences#sync → Sync Now). Repeat the whole thing for each computer with synced temp containers. Subsequent Firefox instances may put temp containers back into your Firefox account sync storage when they start, but these appear to go away when finishing the steps on that profile. I did have to re-do an earlier profile after finishing another computer. The sync did eventually stabilize, and I can sync persistent containers normally again.

At this point, the container sync is still disabled from the code above. Unfortunately, I don't see a way to make sync reliable without something like @stoically's PR at mozilla/multi-account-containers#2231. In the meantime, it seems as if I can run manual syncs when needed:

1. Close/delete the temp containers

2. Enable the Multi-Account Containers' sync option

3. Force a Firefox account sync

4. Disable the Multi-Account Containers' sync option again

Thank you very much for this.

It didn't work for me because the name property of a temporary container object looked like this: "⌚Temporary Container 119". So I placed .substr(1) before .startsWith(prefix):

await Promise.allSettled(
    containers.map(
        container =>
        {
            if (container.name.substr(1).startsWith(prefix))
            {
                return browser.contextualIdentities.remove(container.cookieStoreId);
            }
        }
    )
);

...

const keys = Object.keys(data).filter(k => data[k].name && data[k].name.substr(1).startsWith(prefix));

Then it worked flawlessly.

smlx commented 2 years ago

If you're using wayland on Linux this script might help to clean up tmp containers. Go to about:preferences#containers, run this command in a terminal, and switch focus back to the browser window in the first three seconds. You might need to adjust the number of tabs.

sleep 3; for i in $(seq 10); do wtype -k tab -k tab -k tab -k tab -k tab -k tab -k space; sleep 0.1; done

Once confident in the number of tabs bump the 10 to 100 or so. This solution uses wtype, and allowed me to delete several hundred tmp containers in a few minutes.

neekt commented 1 year ago

Despite all the great proposed solutions in this thread, I have found that the only way to fix the bricked cloud sync issue is to delete your Firefox account and sign up again. It takes ~5-10 mins.

Steps:

  1. Go to accounts.firefox.com/settings, scroll to the bottom and 'Delete Account'. Follow the steps to delete.
  2. In Firefox, go to settings and uncheck 'Enable Container Tabs' - you'll first need to disable any extensions that require container tabs - then re-enable it. N.B. this will reset all containers back to default.
  3. Sign up again. You can sign up again using the same email address. I also strongly recommend enabling two-step authentication.
  4. IMPORTANT: Make sure you repeat step 2 for any other Firefox desktop profile BEFORE you sign in again with the new account. Otherwise you might end up with hundreds of locally stored temporary containers bricking your cloud sync again.
  5. If you want to enable container synchronization, you'll need to disable 'Automatic Mode' in the Temporary Containers extension. Otherwise, again, you might end up with hundreds of temporary containers bricking your cloud sync.

Regarding the last step; if you use "Strict" mode in Firefox's Privacy & Security settings, temporary containers aren't really necessary from a privacy perspective any more, because this mode uses dynamic first-party isolation to isolate cookies anyway. I do still use the extension to create temporary containers manually on occasion though, e.g., if I want to sign into something temporarily.

You'll also need to re-create all of your permanent containers. It's a bit of a pain, but they should all happily sync from now on.

mitchcurtis commented 1 year ago

The related PR that allows excluding containers from sync via regex was just merged: mozilla/multi-account-containers#2231 (comment)

So, hopefully, the next version of multi-account-containers will work flawlessly ❤️

I just checked that now to see if I could find out when it will be released, and noticed this:

https://github.com/mozilla/multi-account-containers/pull/2444

We won't be able to have a fix for https://github.com/mozilla/multi-account-containers/issues/2439 before 8.1.0 is released so we need to backout https://github.com/mozilla/multi-account-containers/pull/2231 and https://github.com/mozilla/multi-account-containers/pull/2383.

So the fix is going to be reverted? :/

ka223 commented 1 year ago

I have countless tmp* containers from past sessions, how can I delete them?

timonoj commented 1 year ago

Install an ADDITIONAL extension called Containers Helper. It helps batch delete containers matching a specific string such as "tmp".

On Tue, Feb 21, 2023 at 1:24 AM Andre @.***> wrote:

I have countless tmp* containers from past sessions, how can I delete them?

— Reply to this email directly, view it on GitHub https://github.com/stoically/temporary-containers/issues/371#issuecomment-1437347110, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACPXB53AOMZRSLEKKOLU6NLWYOSELANCNFSM4KY4O6QA . You are receiving this because you were mentioned.Message ID: @.***>

benediktms commented 1 year ago

For anyon ethat wanst to batch delete containers, I found the UI to be extremly unhelpful especially if you want to delete 100+ containers. The easiest way I found is to just find your containers.json file and and delete the container entries there. Where this file is depends on your OS. For macOS it's: Library/Application Support/Firefox/Profiles/[RELEASE].default-release/containers.json. For linux I think it is somewhere under .mozilla/firefox/.... No idea about windows.

I'd really like to see the ability for users to whitelist containers they want to sync, and to add an option to force overwrite rremote storage from a local FF instance. Until then container sync is unfortunatly not usable.

neekt commented 1 year ago

Note for anyone commenting here that Temporary Containers is no longer maintained, due to the owner and developer of this repository, @stoically, sadly passing away in January (see issue #618 ).

micksmix commented 1 year ago

I wrote a Python script that can clean out containers that start with tmp. It should work cross-platform and will allow you to select the Firefox profile you want to modify: https://gist.github.com/micksmix/4548c3b724f78a930fd330fda3e30661

serhumanos commented 1 year ago

I use "Container Helper" addon to delete the 1064 containers named tmp and they are sync :( every time I disable and reenable MAC sync, the appears again, is there any way to MAC sync remember wich container really are in use and delete the old backed up? (and change the config of my non-tmp containers, color, icon, and related sites.. ie, it change everything)