firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.85k stars 892 forks source link

runTransaction doesn't work in Chrome extension MV3 #6483

Open tarasinf opened 2 years ago

tarasinf commented 2 years ago

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.

MarkDuckworth commented 2 years ago

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?

tarasinf commented 2 years ago

@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.)

tarasinf commented 2 years ago

@MarkDuckworth here is a small Chrome extension example with firebase call. To run it:

I hope you will find an easier way to replicate the issue, as an extension env looks a bit complicated.

MarkDuckworth commented 2 years ago

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?

tarasinf commented 2 years ago

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?

MarkDuckworth commented 2 years ago

I'll have to follow up with you next week regarding the timeline of a fix.

MarkDuckworth commented 2 years ago

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.

Does Firestore Lite meet the needs for your use case?

MarkDuckworth commented 2 years ago

Tracking b/241154587 and b/241157202

tarasinf commented 2 years ago

Thank you, I will try to migrate to Firestore Lite, meantime.

Owillz01 commented 1 year ago

I get this same error message of XMLHttpRequest not defined when trying to use uploadBytesResumable or uploadBytes methods from firebase-storage

capybarahero commented 1 year ago

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.

tom-andersen commented 1 year ago

@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.