首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ReactJS,Redux和DexieJS (IndexedDB) -隐藏模式和Chrome v69中的错误

ReactJS,Redux和DexieJS (IndexedDB) -隐藏模式和Chrome v69中的错误
EN

Stack Overflow用户
提问于 2018-10-14 14:56:50
回答 1查看 1.6K关注 0票数 2

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

堆栈是:

  • 反应
  • 剩馀
  • 反应路由器
  • DexieJS (IndexedDB)

应用程序正在工作。问题是,当我尝试在Firefox或匿名模式(在Chrome中)上测试它时,我会得到以下错误:

TypeError: Cannot read property 'apply' of undefined

有人知道我为什么会犯这个错误吗?我发现IndexedDB在火狐和隐匿模式中是不可用的,所以我尝试做一个简单的检查:

代码语言:javascript
复制
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

谢谢你的帮忙!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-16 21:13:41

IndexedDB在Chrome隐名模式下工作得很好,所以如果你有问题的话,那可能是我的其他原因造成的。

但是你是对的,在火狐的私人浏览模式下,IndexedDB不是很好,尽管你对具体的方式是错误的。在火狐的私有浏览模式中,window.indexedDB不是空的,但是它确实给出了upgradeneeded上的错误。我使用类似的方法来检测它(这也有一些其他的浏览器兼容性检查):

代码语言:javascript
复制
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")
      }
    };
  };
};
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52803941

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档