【问题标题】:ReactJS, Redux and DexieJS (IndexedDB) - Error in incognito mode and Chrome v69ReactJS、Redux 和 DexieJS (IndexedDB) - 隐身模式和 Chrome v69 中的错误
【发布时间】:2018-10-14 14:56:50
【问题描述】:

我目前正在学习 ReactJS,我决定创建一个简单的应用程序。

堆栈是:

  • 反应
  • Redux
  • 反应路由器
  • DexieJS(索引数据库)

应用程序正在运行。问题是当我尝试在 Firefox 或隐身模式(在 Chrome 中)上测试它时,我收到了这个错误:

TypeError: Cannot read property 'apply' of undefined

任何人都知道我为什么会收到此错误以及我该如何处理?我发现IndexedDB在Firefox和隐身模式下都不可用,所以我尝试做一个简单的检查:

if(!window.indexedDB) {
 alert('Indexed DB is not supported by your browser. If you are running in incognito mode, please use the normal mode.')
}

但这不起作用,我再次收到错误。

如果您想查看整个代码,这里是 Github 存储库: https://github.com/Webd01/BM

感谢您的帮助!

【问题讨论】:

    标签: javascript reactjs redux indexeddb


    【解决方案1】:

    IndexedDB 在 Chrome 隐身模式下工作正常,所以如果你在那里遇到问题,可能是我的其他问题造成的。

    但是你是对的,IndexedDB 在 Firefox 隐私浏览模式下不好,虽然你错了具体如何。 window.indexedDB 在 Firefox 隐私浏览模式下不为空,但在 upgradeneeded 上确实会出现错误。我使用类似的东西来检测它(这也有一些其他浏览器兼容性检查):

    var checkIDB = function () {
      if (typeof window.indexedDB === "undefined") {
        console.log("IndexedDB not supported at all!");
        return;
      }
    
      try {
        keyRange.only([1]);
      } catch (e) {
        console.log("Buggy Microsoft IndexedDB implementation");
        return;
      }
    
      var openRequest = window.indexedDB.open('firefox-private-test', 1);
    
      openRequest.onerror = function (evt) {
        console.error(evt.target.error);
        if (evt.target.error.message.includes("aborted")) {
          console.log("Some other error, maybe quota related:");
          console.log(evt.target.error);
        } else {
          console.log("Firefox private mode, probably:");
          console.log(evt.target.error);
        }
      }
    
      openRequest.onupgradeneeded = function (evt) {
        var db = evt.target.result;
        var one = db.createObjectStore('one', {
          autoIncrement: true,
          keyPath: 'key'
        });
        one.createIndex('one', 'one');
        one.add({one: 1});
        var two = db.createObjectStore('two', {
          autoIncrement: true,
          keyPath: 'key'
        });
        two.createIndex ('two', 'two');
        two.add({two: 2});
      };
    
      openRequest.onsuccess = function (evt) {
        var db = evt.target.result;
        var transaction;
        try {
          transaction = db.transaction(['one', 'two'], 'readwrite');
        } catch (e) {
          console.log("Some browser failed here, maybe an old version of Safari, I forget");
          console.log(e.target.error);
          return;
        }
    
        var count = 0;
        transaction.objectStore('one').index('one').openCursor().onsuccess = function (evt) {
          cursor = evt.target.result;
          if (cursor) {
            count += 1;
            cursor.continue();
          }
        };
    
        transaction.oncomplete = function () {
          db.close();
          if (count === 1) {
            console.log("All good!");
          } else {
            console.log("Buggy Safari 10 IndexedDB implementation")
          }
        };
      };
    };
    

    【讨论】:

    • 谢谢!完美运行
    猜你喜欢
    • 1970-01-01
    • 2018-11-23
    • 2017-12-05
    • 2016-06-11
    • 1970-01-01
    • 2018-12-02
    • 2017-12-19
    • 2016-11-07
    • 2021-07-11
    相关资源
    最近更新 更多