What is safari-14-idb-fix?
The safari-14-idb-fix npm package provides a workaround for a known issue in Safari 14 where IndexedDB operations can fail due to a bug in the browser. This package ensures that IndexedDB operations work reliably in Safari 14 by applying necessary fixes.
What are safari-14-idb-fix's main functionalities?
Apply Fix for Safari 14 IndexedDB Bug
This feature applies the necessary fix to ensure that IndexedDB operations do not fail in Safari 14. By calling `applySafari14IDBFix()`, you can safely use IndexedDB in your application without worrying about the Safari 14 bug.
const { applySafari14IDBFix } = require('safari-14-idb-fix');
applySafari14IDBFix();
// Now you can safely use IndexedDB in Safari 14
const request = indexedDB.open('my-database');
request.onsuccess = function(event) {
const db = event.target.result;
// Perform database operations
};
Other packages similar to safari-14-idb-fix
idb
The idb package is a well-known wrapper for IndexedDB that simplifies its usage with a promise-based API. While it does not specifically address the Safari 14 bug, it provides a more user-friendly interface for working with IndexedDB.
dexie
Dexie is a powerful wrapper for IndexedDB that offers a rich set of features, including a promise-based API, easy-to-use queries, and support for transactions. Like idb, it does not specifically target the Safari 14 bug but enhances the overall experience of working with IndexedDB.
localforage
LocalForage is a library that provides a simple API for storing data in various storage backends, including IndexedDB, WebSQL, and localStorage. It abstracts away the complexities of these storage mechanisms and offers a unified interface. While it does not specifically address the Safari 14 bug, it provides a versatile solution for client-side storage.
Safari 14 IndexedDB fix
Safari on macOS Big Sur 11.4 and iOS 14.6 has a nasty bug where IndexedDB requests get lost and never resolve. The issue was fixed in Safari 14.7.
This library (well, function) works around the issue and tells you when IndexedDB is actually available.
To install:
npm i safari-14-idb-fix
To use:
import idbReady from 'safari-14-idb-fix';
idbReady().then(() => {
});
All bundles
A modern build tool will handle the above example fine, but if you need a specific build:
safari-14-idb-fix/dist/index.js
EcmaScript module.safari-14-idb-fix/dist/index.cjs
CommonJS module.safari-14-idb-fix/dist/iife.min.js
Minified plain JS, which creates an idbReady
global.