ReactJS、Redux 和 DexieJS (IndexedDB) - 隐身模式错误和 Chrome v69
ReactJS, Redux and DexieJS (IndexedDB) - Error in incognito mode and Chrome v69
我目前正在学习 ReactJS,我决定创建一个简单的应用程序。
堆栈是:
- 反应
- Redux
- 反应路由器
- DexieJS(索引数据库)
应用程序正在运行。问题是,当我尝试在 Firefox 或隐身模式(Chrome)上测试它时,我收到此错误:
TypeError: Cannot read property 'apply' of undefined
有人知道我为什么会收到此错误以及我该如何处理吗?我发现 IndexedDB 在 Firefox 和 incognito 模式下不可用,所以我尝试做一个简单的检查:
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
感谢您的帮助!
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")
}
};
};
};
我目前正在学习 ReactJS,我决定创建一个简单的应用程序。
堆栈是:
- 反应
- Redux
- 反应路由器
- DexieJS(索引数据库)
应用程序正在运行。问题是,当我尝试在 Firefox 或隐身模式(Chrome)上测试它时,我收到此错误:
TypeError: Cannot read property 'apply' of undefined
有人知道我为什么会收到此错误以及我该如何处理吗?我发现 IndexedDB 在 Firefox 和 incognito 模式下不可用,所以我尝试做一个简单的检查:
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
感谢您的帮助!
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")
}
};
};
};