Skip to content

Fix 'window is not defined' error when calling clearIndexedDbPersistence #8888

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

Merged
merged 1 commit into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/gentle-rocks-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@firebase/firestore': patch
'firebase': patch
---

Fix 'window is not defined' error when calling `clearIndexedDbPersistence` from a service worker
1 change: 1 addition & 0 deletions packages/firestore/externs.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"packages/util/dist/src/emulator.d.ts",
"packages/util/dist/src/environment.d.ts",
"packages/util/dist/src/compat.d.ts",
"packages/util/dist/src/global.d.ts",
"packages/util/dist/src/obj.d.ts",
"packages/firestore/src/protos/firestore_bundle_proto.ts",
"packages/firestore/src/protos/firestore_proto_api.ts",
Expand Down
9 changes: 6 additions & 3 deletions packages/firestore/src/local/simple_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { getUA, isIndexedDBAvailable } from '@firebase/util';
import { getGlobal, getUA, isIndexedDBAvailable } from '@firebase/util';

import { debugAssert } from '../util/assert';
import { Code, FirestoreError } from '../util/error';
Expand All @@ -24,7 +24,7 @@ import { Deferred } from '../util/promise';

import { PersistencePromise } from './persistence_promise';

// References to `window` are guarded by SimpleDb.isAvailable()
// References to `indexedDB` are guarded by SimpleDb.isAvailable() and getGlobal()
/* eslint-disable no-restricted-globals */

const LOG_TAG = 'SimpleDb';
Expand Down Expand Up @@ -164,7 +164,10 @@ export class SimpleDb {
/** Deletes the specified database. */
static delete(name: string): Promise<void> {
logDebug(LOG_TAG, 'Removing database:', name);
return wrapRequest<void>(window.indexedDB.deleteDatabase(name)).toPromise();
const globals = getGlobal();
return wrapRequest<void>(
globals.indexedDB.deleteDatabase(name)
).toPromise();
}

/** Returns true if IndexedDB is available in the current environment. */
Expand Down
Loading