Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIrefox Private Browsing: A mutation operation was attempted on a database that did not allow mutations #5377

Closed
piperone opened this issue Aug 25, 2021 · 8 comments · Fixed by #5396

Comments

@piperone
Copy link

  • Operating System version: _____macOS Big Sur 11.5.2
  • Browser version: _____ Firefox Developer Edition 92.0b6 (64bit)
  • Firebase SDK version: _____8.3.1
  • Firebase Product: _____ auth, firestore

Steps to reproduce:

I'm seeing the error "A mutation operation was attempted on a database that did not allow mutations" when starting my app in Firefox' private browsing mode. This was reported in #4069 and fixed in #4146 (8.1.2) so could this be a regression?

Exact error message:
Uncaught (in promise) IndexedDbTransactionError: IndexedDB transaction 'getHighestListenSequenceNumber' failed: InvalidStateError: A mutation operation was attempted on a database that did not allow mutations.

@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@dconeybe
Copy link
Contributor

Hi @piperone. Based on the error message this doesn't appear to be a duplicate of #4069. Specifically, getHighestListenSequenceNumber is part of Firestore:

return this.runTransaction(
'getHighestListenSequenceNumber',
'readonly',
txn => this.targetCache.getHighestSequenceNumber(txn)
);
which is a completely different part of the code than #4146 addressed. The IndexedDB error is the same but the culprit is somewhere else. I'll look into it and get back to you.

In the meantime, could you try upgrading to the latest version, namely 8.10.0 (the bug report indicates that you are using a 5-month-old version: 8.3.1)? Also, if you are able to provide a minimal reproduction app that could greatly speed up the investigation. If not, is there a code snippet you could provide that causes the error?

@piperone
Copy link
Author

@dconeybe Thanks a bunch for addressing the issue so promptly, appreciate it. You're right of course, I was on an outdated version of firebase. Updating to 8.10.0 unfortunately didn't remove the error.

I'm using firebase along with Vue and a UI component framework called Quasar. Running my Quasar app is when I get the error. Here's the init code I use for Firebase:

import firebase from 'firebase/app';
import 'firebase/firestore';

const firebaseApp = firebase
  .initializeApp({
    // My credentials
  });

// Get a Firestore instance
const db = firebaseApp.firestore();

db.settings({
  persistence: true,
});

db.enablePersistence({
  synchronizeTabs: true,
});

If you need to see this in action, I created a minimal Quasar app repo. BTW, Quasar has its own CLI which I recommend in order to run my example.

  1. Clone the repo
  2. Find src/App.vue and insert Firebase credentials in the initializeApp()-call,
  3. Install NPM dependencies
  4. Run quasar dev
  5. Open the app in private browsing on Firefox and you should see the error in the console

@dconeybe
Copy link
Contributor

@piperone Thank you for all of that information. I haven't tried out your sample app yet but after a bit of research I'm wondering if this may be due to Firefox's lack of support for IndexedDB in private browsing sessions.

Could you try the workaround documented at https://bugzilla.mozilla.org/show_bug.cgi?id=1639542#c9 to see if it fixes the issue?

There's an about:config workaround by setting dom.indexedDB.privateBrowsing.enabled to true Of course this will forego the privacy guarantees of private browsing...

Obviously, this isn't a real solution for customers but it would confirm whether or not the absence of IndexedDB support is the culprit.

@dconeybe
Copy link
Contributor

Update: I've confirmed that the culprit is lack of IndexedDB support in Firefox private browsing. Off the top of my head, I can think of two options:

  1. Use the workaround identified in the previous comment.
  2. Disable persistence (i.e. remove the call to db.settings({ persistence: true })).

I'm pretty sure that all we can do in Firestore is fail more gracefully in this scenario, which I'll investigate.

@piperone
Copy link
Author

Understood. Neither of your suggestions are viable for me unfortunately. It's still early days for the app I'm working on, so it's not a pressing matter. It'd be good if this case was handled with more grace by the library in the future, of course.

Thanks again.

@dconeybe
Copy link
Contributor

dconeybe commented Sep 2, 2021

I've merged a fix to improve the error message: #5396.

Note that when you try to enable persistence in a Firefox private browsing session it is failing to open an IndexedDB connection and therefore is falling back to "memory persistence", a.k.a. no persistence. So firestore will still work just fine, but there will effectively be no persistence. Maybe this is acceptable since it is a private browsing session anyways which I'd expect wouldn't persist stuff.

@piperone
Copy link
Author

piperone commented Sep 3, 2021

Thanks for your work on this, I appreciate it. Even though fixing the error isn't possible at your end currently, a more descriptive error-message should help devs in the future.

For my particular app, I'll probably disallow using private browsing sessions; it's an app used by a small number of expert users. It doesn't make sense with private browsing in my usecase anyway.

Thanks again!

@firebase firebase locked and limited conversation to collaborators Oct 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants