Working around a Safari IndexedDB bug

Overview

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.

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(() => {
  // Safari has figured out where IndexedDB is.
  // You can use IndexedDB as usual.
});

All bundles

A modern build tool will handle the above example fine, but if you need some different builds:

  • dist/cjs/index.js CommonJS module.
  • dist/cjs-compat/index.js CommonJS module, transpiled for older browsers.
  • dist/esm/index.js EcmaScript module.
  • dist/esm-compat/index.js EcmaScript module, transpiled for older browsers.
  • dist/iife/index-min.js Minified plain JS, which creates an idbReady global.
  • dist/iife-compat/index-min.js As above, but transpiled for older browsers.
Comments
  • Refer

    Refer "module" field to esm-compat

    If I have interpreted the package.json fields conventions jungle correctly, the "module" field would be a way to point to an ES2015-based module but in all other aspects, only containing ES5-compatible JS code.

    Found the issue as I integrated this module into dexie as a devDependencie, using rollup to include it. Rollup is run after transpilation and when it finds the "module" field, it integrates that module into my final ES5 code. When the CI tests sends this to browserstack for IE11 testing - it fails.

    I don't know why I'm still maintaining dexie for IE11 though in 2021, but, I'm just in a minor release so I currently need to stick to it.

    opened by dfahlander 3
  • fix: fix for older Safari versions

    fix: fix for older Safari versions

    According to MDN, Safari didn't ship indexedDB.databases() until v14. I can confirm that on iOS 12.5.3, Safari throws an error in this library because the API is missing.

    It seems reasonable to me to just return Promise.resolve() for older versions of Safari.

    opened by nolanlawson 3
  • Don't crash if navigator is unavailable

    Don't crash if navigator is unavailable

    Note: I haven't tested this; I'm submitting it from the github editor.

    When using fake-indexeddb with node (for unit testing), safari-14-idb-fix crashes with "ReferenceError: navigator is not defined". If navigator is not defined, then it clearly isn't safari, so I added the existence check.

    opened by dusty-phillips 2
  • Type: module in package.json

    Type: module in package.json

    Getting following error building a sveltekit project. Setting "type": "module" as suggested fixed it:

    (node:51281) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
    (Use `node --trace-warnings ...` to show where the warning was created)
    > Cannot use import statement outside a module
    /Users/holdph/personal/song-kit/node_modules/idb-keyval/dist/esm/index.js:1
    import safariFix from 'safari-14-idb-fix';
    ^^^^^^
    
    SyntaxError: Cannot use import statement outside a module
        at compileFunction (<anonymous>)
        at Object.compileFunction (node:vm:353:18)
        at wrapSafe (node:internal/modules/cjs/loader:1039:15)
        at Module._compile (node:internal/modules/cjs/loader:1073:27)
        at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
        at Module.load (node:internal/modules/cjs/loader:989:32)
        at Function.Module._load (node:internal/modules/cjs/loader:829:14)
        at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:201:29)
        at ModuleJob.run (node:internal/modules/esm/module_job:175:25)
        at async Loader.import (node:internal/modules/esm/loader:178:24)
    error Command failed with exit code 1.
    
    opened by philholden 2
  • Simplify Variants

    Simplify Variants

    The ES5 "compat" version of safari-14-idb-fix was actually 2b smaller than the default (modern) version. Since the differences between the two were limited to "function" vs arrows and const vs var, there should also be no measurable performance tradeoff. Simplifying the package by shipping only ES5 will help ease usage in bundlers/runtimes with varying support for Package Exports.

    The new directory layout is:

    dist/
        index.js  <- ESM
        index.cjs  <- CJS
        iife.min.js  <- IIFE
        index.d.ts  <- types
    

    All are ES5, all are minified via Terser.

    opened by developit 1
  • Simplify Package Exports

    Simplify Package Exports

    This PR simplifies package exports by removing intermediary directories in favor of .js / .cjs for differentiation. This also allows folks to import safari-14-idb-fix/dist/index.cjs directly if desired.

    opened by developit 1
  • Avoid checking `userAgent` in Chrome

    Avoid checking `userAgent` in Chrome

    You'll get a DevTools "improvement" suggested for accessing navigator.userAgent. One might realistically expect this issue to be fixed before Safari adds support for navigator.userAgentData, so this feels like a reasonable addition just in case you want to give it a whirl.

    opened by rowan-m 1
  • Unhandled promise rejection: The operation is insecure.

    Unhandled promise rejection: The operation is insecure.

    Hi, our monitoring tool (trackJS) report us the Promise here:

    Screenshot 2022-11-07 104201

    crashes with an "The operation is insecure" error from time to time, even in "modern" safari browsers (safari 15.4+)

    I couldn't manage to recreate the exact error conditions but I believe this might happen when the IndexedDB is disabled in the browser. Is there a check we neeed to add to detect this before it crashes?

    opened by thurfir 0
  • Expand user agent check

    Expand user agent check

    I'm running a Cordova app on IOS 14.6 on an iPhone SE and it has the same behavior of hanging on openDB. Was hoping to use this 'function' to add a temporary shim to work around the issue.

    However, current code checks for 'Safari' in the UA. In my case, it's in Cordova/Webkit not Safari - so the UA returned is:

    Mozilla/5.0 (iPhone; CPU iPhone OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148.

    I'm not sure how wide to expand the test to prevent perf issues on other platforms - maybe 'Safari' and 'AppleWebKit' ? or look at the 14_x version?

    opened by brettmarl 0
Owner
Jake Archibald
Jake Archibald
A simple Multi Guild Modmail Bot coded in v13 using the enmap Database Working on any host, like repl.it or vps! Its fast and working bug free + Security options!

Multiguild-Modmail A simple Multi Guild Modmail Bot coded in v13 using the enmap Database Working on any host, like repl.it or vps! Its fast and worki

Tomato6966 54 Oct 20, 2022
Bugs bugging you? Bug back.

bugger Warning: Experimental bugger provides Chrome Devtools bindings for node. It integrates tightly with Chrome which means two things: It attempts

bugger 157 Aug 8, 2022
Safari-like start page

Safari-like Start Page Safari-like Start Page - Online Preview Installation clone this repo # Clone the repo # Using HTTPS git clone https://github.c

Louis 8 Dec 8, 2022
Chrome/Safari/Firefox extension for clipping arXiv articles to Notion.

arxiv2notion+ Easy-to-use arXiv clipper for Notion based on Notion API (original repo: https://github.com/denkiwakame/arxiv2notion MIT License) Downlo

Jingkang Wang 51 Nov 24, 2022
This is a demo for Remix SPA's via Service Worker. (doesn't currently work in Safari)

Welcome to Remix! Remix Docs Development From your terminal: npm run dev This starts your app in development mode, rebuilding assets on file changes.

Jacob Ebey 3 Oct 2, 2022
A tool for increasing the off-by-one bug in ordinal explorers

Breaker of jpegs A tool for increasing the off-by-one bug in ordinal explorers How to break inscription numbers On 2023-05-04 I introduced an off-by-o

null 63 Aug 9, 2023
Base Bot WhatsApp With Baileys Multi Device, Working Heroku No Suspend ☑️, Working Okteto No Suspend ☑️

Base Bot WhatsApp Multi Device With Baileys Multi Device Note Base Ini Free Untuk Semua, Tidak Untuk Diperjualbelikan Kecuali Lu Udah Tambahin Fitur L

Nazril Afandi 36 Dec 25, 2022
AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.

Please use version 1.x as prior versions has a security flaw if you use user generated data to concat your SQL strings instead of providing them as a

Andrey Gershun 6.1k Jan 9, 2023
💾 Offline storage, improved. Wraps IndexedDB, WebSQL, or localStorage using a simple but powerful API.

localForage localForage is a fast and simple storage library for JavaScript. localForage improves the offline experience of your web app by using asyn

localForage 21.5k Jan 4, 2023
db.js is a wrapper for IndexedDB to make it easier to work against

db.js db.js is a wrapper for IndexedDB to make it easier to work against, making it look more like a queryable API. Usage Add a reference to db.js in

Aaron Powell 790 Nov 28, 2022
💾 Offline storage, improved. Wraps IndexedDB, WebSQL, or localStorage using a simple but powerful API.

localForage localForage is a fast and simple storage library for JavaScript. localForage improves the offline experience of your web app by using asyn

localForage 21.5k Jan 1, 2023
sqlite3 in ur indexeddb

This is an absurd project. It implements a backend for sql.js (sqlite3 compiled for the web) that treats IndexedDB like a disk and stores data in bloc

James Long 3.6k Jan 4, 2023
sqlite3 in ur indexeddb

This is an absurd project. It implements a backend for sql.js (sqlite3 compiled for the web) that treats IndexedDB like a disk and stores data in bloc

James Long 3.6k Dec 30, 2022
Demo showcasing information leaks resulting from an IndexedDB same-origin policy violation in WebKit.

Safari 15 IndexedDB Leaks Description This demo showcases information leaks resulting from an IndexedDB same-origin policy violation in WebKit (a brow

FingerprintJS 101 Nov 5, 2022
PouchDB for Deno, leveraging polyfill for IndexedDB based on SQLite.

PouchDB for Deno PouchDB for Deno, leveraging polyfill for IndexedDB based on SQLite. Usage import PouchDB from 'https://deno.land/x/[email protected]

Aaron Huggins 19 Aug 2, 2022
IndexedDB with usability and remote syncing

IndexedDB with usability and remote syncing This is a fork of the awesome idb library, which adds the ability to sync an IndexedDB database with a rem

Damien Arrachequesne 8 Dec 14, 2022
fetch and process data in web worker, store in indexedDB.

Query+ install yarn add query-plus or pnpm add query-plus or npm install query-plus import import { useFetch, usePreFetch } from "query-plus" use

Rod Lewis 5 Aug 29, 2022
Browser storage interface for IndexedDB, WebSQL, LocalStorage, and in memory data with Schema and data validator.

Client Web Storage Browser storage interface for IndexedDB, WebSQL, LocalStorage, and in memory data with basic Schema and data validation. Installati

Before Semicolon 19 Sep 30, 2022
❇️ Doxor.js : more comfortable interacting with IndexedDB

doxor.js Offline database in Front-End library for interacting with IndexedDB Install Doxor.js using npm npm i doxor.js Creating a database import Do

Mojtaba Afraz 20 Oct 3, 2022
Persistent key/value data storage for your Browser and/or PWA, promisified, including file support and service worker support, all with IndexedDB. Perfectly suitable for your next (PWA) app.

BrowstorJS ?? ?? ?? Persistent key/value data storage for your Browser and/or PWA, promisified, including file support and service worker support, all

Nullix 8 Aug 5, 2022