我目前正在学习ReactJS,我决定创建一个简单的应用程序。
堆栈是:
应用程序正在工作。问题是,当我尝试在Firefox或匿名模式(在Chrome中)上测试它时,我会得到以下错误:
TypeError: Cannot read property 'apply' of undefined

有人知道我为什么会犯这个错误吗?我发现IndexedDB在火狐和隐匿模式中是不可用的,所以我尝试做一个简单的检查:
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
谢谢你的帮忙!
发布于 2018-10-16 21:13:41
IndexedDB在Chrome隐名模式下工作得很好,所以如果你有问题的话,那可能是我的其他原因造成的。
但是你是对的,在火狐的私人浏览模式下,IndexedDB不是很好,尽管你对具体的方式是错误的。在火狐的私有浏览模式中,window.indexedDB不是空的,但是它确实给出了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")
}
};
};
};https://stackoverflow.com/questions/52803941
复制相似问题