'use strict'; /** * https://bugs.webkit.org/show_bug.cgi?id=226547 * Safari has a horrible bug where IDB requests can hang while the browser is starting up. * The only solution is to keep nudging it until it's awake. * This probably creates garbage, but garbage is better than totally failing. */ function idbReady() { var isSafari = !navigator.userAgentData && /Safari\//.test(navigator.userAgent) && !/Chrom(e|ium)\//.test(navigator.userAgent); // No point putting other browsers or older versions of Safari through this mess. if (!isSafari || !indexedDB.databases) return Promise.resolve(); var intervalId; return new Promise(function (resolve) { var tryIdb = function tryIdb() { return indexedDB.databases().finally(resolve); }; intervalId = setInterval(tryIdb, 100); tryIdb(); }).finally(function () { return clearInterval(intervalId); }); } module.exports = idbReady;