index.js 897 B

12345678910111213141516171819202122
  1. /**
  2. * Work around Safari 14 IndexedDB open bug.
  3. *
  4. * Safari has a horrible bug where IDB requests can hang while the browser is starting up. https://bugs.webkit.org/show_bug.cgi?id=226547
  5. * The only solution is to keep nudging it until it's awake.
  6. */
  7. function idbReady() {
  8. var isSafari = !navigator.userAgentData &&
  9. /Safari\//.test(navigator.userAgent) &&
  10. !/Chrom(e|ium)\//.test(navigator.userAgent);
  11. // No point putting other browsers or older versions of Safari through this mess.
  12. if (!isSafari || !indexedDB.databases)
  13. return Promise.resolve();
  14. var intervalId;
  15. return new Promise(function (resolve) {
  16. var tryIdb = function () { return indexedDB.databases().finally(resolve); };
  17. intervalId = setInterval(tryIdb, 100);
  18. tryIdb();
  19. }).finally(function () { return clearInterval(intervalId); });
  20. }
  21. export default idbReady;