Skip to content

"supportsIndexedDB" is malfunctioning in some cases #990

Description

@xulww

While using Orbit, I encountered an issue with the "supportsIndexedDB" function, which seems to be malfunctioning.

Upon testing in Chrome's incognito mode, the function correctly returns true, indicating support for indexedDB. However, when testing Firefox's private browsing mode, the function also returns true, which is incorrect. In reality, Firefox's private browsing mode does not allow the use of indexedDB, resulting in error messages such as error opening indexedDB *db-name* and DOMException: A mutation operation was attempted on a database that did not allow mutations.

To clarify, Firefox explicitly prohibits mutations to indexedDB while in private browsing mode. As a result, the "supportsIndexedDB" function should accurately reflect this behavior, returning false in such scenarios.

In my opinion, a more effective approach to handle checks for indexedDB support would involve something similar to this code:

function getIsIndexedDBSupported() {
    return new Promise((resolve) => {
        if (!window.indexedDB) {
            resolve(false);
            return;
        }

        try {
            const dbName = "testDB";
            const request = window.indexedDB.open(dbName, 1);

            request.onerror = () => {
                resolve(false);
            };

            request.onsuccess = (event) => {
                const db = event.target.result;

                db.close();

                window.indexedDB.deleteDatabase(dbName);

                resolve(true);
            };
        } catch (error) {
            resolve(false);
        }
    });
};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions