clearIndexedDbPersistence gives 'window is not defined' error in service worker (original) (raw)

Environment

Problem

Steps to reproduce

  1. Setup a Manifest V3 Chrome Extension with a service worker. (not necessary, see notes -> 1)
  2. Use enableIndexedDbPersistence(firebase, { forceOwnership: true }) in the service worker to setup persistence.
  3. Verify in the storage tab that indexeddb storage is enabled, great!
  4. 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

  1. 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.
  2. I had earlier asked a StackOverflow question for this.