Javascript ReactJS、Redux和DexieJS(IndexedDB)-在匿名模式和Chrome v69中出错

Javascript ReactJS、Redux和DexieJS(IndexedDB)-在匿名模式和Chrome v69中出错,javascript,reactjs,redux,indexeddb,Javascript,Reactjs,Redux,Indexeddb,我目前正在学习ReactJS,我决定创建一个简单的应用程序 堆栈是: 反应 重演 反应路由器 DexieJS(IndexedDB) 应用程序正在运行。问题是,当我尝试在Firefox或匿名模式(在Chrome中)上测试它时,会出现以下错误: TypeError:无法读取未定义的属性“apply” 有人知道我为什么会犯这个错误,以及我如何处理这个错误吗?我发现IndexedDB在Firefox和匿名模式下不可用,所以我尝试做一个简单的检查: if(!window.indexedDB) {

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

堆栈是:

  • 反应
  • 重演
  • 反应路由器
  • DexieJS(IndexedDB)
应用程序正在运行。问题是,当我尝试在Firefox或匿名模式(在Chrome中)上测试它时,会出现以下错误:


TypeError:无法读取未定义的属性“apply”

有人知道我为什么会犯这个错误,以及我如何处理这个错误吗?我发现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 repo:


谢谢你的帮助

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")
      }
    };
  };
};