runTransaction doesn't work in Chrome extension MV3
- Operating System version: Ubuntu 20.04.3 LTS
- Browser version: 102.0.5005.61
- Firebase SDK version: 9.6.5
- Firebase Product: firestore
- Chrome extension: VM3
The problem
I can't use runTransaction in Chrome extension MV3 as it doesn't support XMLHttpRequest. All other commands work well.
I found that it was fixed on GH (for some reasons, not for transactions).
Steps to reproduce:
let userRef = doc(db, 'users', userInfo.id);
runTransaction(db, transaction => {
return transaction.get(userRef).then(userDoc => {
return transaction.update(userRef, { 'eventName': 42 });
});
});
I got an error: Uncaught (in promise) FirebaseError: ReferenceError: XMLHttpRequest is not defined
My assumption is that V9 still uses XMLHttpRequest in runTransaction.
Thanks for bringing this to our attention. This is in my queue to investigate. In the meantime, is it possible for you to provide us with a minimal reproducible example so we can quickly reproduce the issue in same environment your code is executing in?
@MarkDuckworth thank you for the quick response. I can prepare a small chrome expansion project. Will it work for you?
(Or, in case it's possible, you can try to run the code above under some env that doesn't support XMLHttpRequest.)
@MarkDuckworth here is a small Chrome extension example with firebase call. To run it:
- update values in
manifest.json:,extension_ids,client_id,key - update
firebaseConfiginbakground.js - import extension, click on the icon, press button.
- in
service workerdebug tool you will be able to see the errorUncaught (in promise) FirebaseError: ReferenceError: XMLHttpRequest is not defined
I hope you will find an easier way to replicate the issue, as an extension env looks a bit complicated.
Thank you. I was able to reproduce this using the code you provided. I have moved the bug to our internal tracking system and will update you when we have a fix planned.
In the meantime, are you able to work around this without using transactions?
Thank you @MarkDuckworth,
It would be much, much better to have transactions. I am going to implement a counter (per user) to know the number of items. Without transactions, I am doing .size() - what's a heavy operation.
Do you have any ideas, how long will it tale to implement the fix?
I'll have to follow up with you next week regarding the timeline of a fix.
I reviewed this in depth today. The required changes are non-trivial. At this point I can only say that this is in our backlog to be scheduled in a future sprint.
However, I did notice that Firestore Lite uses fetch() instead of XMLHttpRequest. I was able use runTransaction in a service worker of a MV3 Chrome extension when using Firestore Lite.
Tracking b/241154587 and b/241157202
Thank you, I will try to migrate to Firestore Lite, meantime.
I get this same error message of XMLHttpRequest not defined when trying to use uploadBytesResumable or uploadBytes methods from firebase-storage
Hey there, are there any updates on this issue? I am unfortunately experiencing the same problem and can't migrate into Firestore Lite at the moment.
@capybarahero Jumping in while @MarkDuckworth is on vacation.
We are still tracking this. However, we are in the midst of planning new query features, so I don't feel comfortable making any promises at this time. But I will raise this with the team, as we might be able to find some resources to deprecate usage of XMLHttpRequest.
Hang tight, we know this is a limitation when using extensions and service workers.