clearIndexedDbPersistence gives 'window is not defined' error in service worker
Environment
- Operating System version: Windows 10/Ubuntu 22.04
- Browser version: Chrome 103/104/105
- Firebase SDK version: 9.9.0
- Firebase Product: firestore
Problem
Steps to reproduce
- Setup a Manifest V3 Chrome Extension with a service worker. (not necessary, see notes -> 1)
- Use
enableIndexedDbPersistence(firebase, { forceOwnership: true })in the service worker to setup persistence. - Verify in the storage tab that indexeddb storage is enabled, great!
- Now, call
clearIndexedDbPersistence()to remove all data from the indexeddb.
Actual result
Uncaught (in promise) ReferenceError: window is not defined
at Yl.delete (index.esm2017.js:6055:59)
at index.esm2017.js:16720:26
at index.esm2017.js:16717:19
at index.esm2017.js:16308:54
Expected result
The indexed DB should be cleared.
Notes
- I don't think the problem is specific to MV3 Chrome extensions, but I don't have any other service worker environment to try this in.
- I had earlier asked a StackOverflow question for this.
Hi team! Is there any update on this issue? In the mean time, is there any other alternative code so as to manually clear the Firebase IndexedDB ourselves?
Hi @GaurangTandon , sorry for the long wait on this ticket.
I assume you are using a newer version of the Firebase SDK( not the v9.9.0 in the description) and the problem still exists, correct?
Could you please provide a minimal repro app to reproduce this error?
Hi @milaGGL I am still able to reproduce the issue on the latest version. The stack trace has changed to this now:
Uncaught (in promise) ReferenceError: window is not defined
at ts.delete (index.esm2017.js:1664:95)
at index.esm2017.js:18823:42
at index.esm2017.js:18820:19
at index.esm2017.js:18400:54
I have added a minimal repro at this drive link: https://drive.google.com/file/d/1QUBEMtaoEf4SHSa2j3yORWn739nDd4_9/view?usp=sharing
After you download the zip file, here's a video showing step by step to repro the issue: https://github.com/firebase/firebase-js-sdk/assets/6308683/69f6f094-b7db-43f6-b34a-7879717a379c
You can swap manifest.json contents with mv2.json/mv3.json (as I have done in the video) and observe the error in mv3 version. This is because mv3 version uses a service worker (which doesn't have a window defined globally), whereas mv2 version does have window defined globally.
@GaurangTandon, I am able to reproduce this error, will start looking into the root cause ASAP.