Skip to content
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

"supportsIndexedDB" is malfunctioning in some cases #990

Open
xulww opened this issue May 23, 2023 · 0 comments
Open

"supportsIndexedDB" is malfunctioning in some cases #990

xulww opened this issue May 23, 2023 · 0 comments

Comments

@xulww
Copy link

xulww commented May 23, 2023

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);
        }
    });
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant