From 5e3a39cb69af62326b25202a387bbeb52e6b3e38 Mon Sep 17 00:00:00 2001 From: Clark Fischer Date: Mon, 9 Jan 2023 20:21:09 -0800 Subject: [PATCH] Allow IndexedDB cleanup operations to fail Firefox ships with a preference (`dom.indexedDB.privateBrowsing.enabled`) which causes `window.indexedDB` to fail on all requests including `deleteDatabase`. Because of that, Firefox Private Browsing users are left with an infinite loading spinner. `MatrixClient#clearStores` will resolve to a rejected promise if any of its operations fails, which seems correct -- it's unable to complete its tasks. So, to keep from erroring out during initialization, the errors have to be discarded during the lifecycle operations. Signed-off-by: Clark Fischer --- src/Lifecycle.ts | 10 ++++++++-- test/Lifecycle-test.ts | 44 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 test/Lifecycle-test.ts diff --git a/src/Lifecycle.ts b/src/Lifecycle.ts index 30aab429fb7..b1e3eb1b896 100644 --- a/src/Lifecycle.ts +++ b/src/Lifecycle.ts @@ -2,7 +2,7 @@ Copyright 2015, 2016 OpenMarket Ltd Copyright 2017 Vector Creations Ltd Copyright 2018 New Vector Ltd -Copyright 2019, 2020 The Matrix.org Foundation C.I.C. +Copyright 2019 - 2023 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -926,7 +926,13 @@ async function clearStorage(opts?: { deleteEverything?: boolean }): Promise { + // Return an IDBOpenDBRequest that immediately errors + const resp = { onerror: undefined } as IDBOpenDBRequest; + setTimeout(() => resp.onerror?.(new ErrorEvent("")), 1); + return resp; + }, + } as unknown as IDBFactory; +} + +describe("Lifecycle", () => { + describe("onLoggedOut", () => { + beforeAll(() => mockPlatformPeg()); + + it("allows IndexedDB failures", async () => { + // Ensure that the indexedDB error is not propagated. + globalThis.indexedDB = brokenIDB(); + await Lifecycle.onLoggedOut(); + }); + }); +});