1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-06 09:37:12 +02:00
This commit is contained in:
gorhill 2017-10-21 08:43:45 -04:00
parent 95f2fb6b11
commit 3e35f10c25
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -110,18 +110,39 @@ vAPI.cacheStorage = (function() {
if ( pending.length !== 1 ) { return; }
// This will fail in private browsing mode.
var req = indexedDB.open(STORAGE_NAME, 1);
// https://github.com/gorhill/uBlock/issues/3156
// I have observed that no event was fired in Tor Browser 7.0.7 +
// medium security level after the request to open the database was
// created. When this occurs, I have also observed that the `error`
// property was already set, so this means uBO can detect here whether
// the database can be opened successfully. A try-catch block is
// necessary when reading the `error` property because we are not
// allowed to read this propery outside of event handlers in newer
// implementation of IDBRequest (my understanding).
try {
if ( req.error ) {
console.log(req.error);
processPendings();
pending = undefined;
return;
}
} catch(ex) {
}
req.onupgradeneeded = function(ev) {
req = undefined;
db = ev.target.result;
db.onerror = db.onabort = genericErrorHandler;
var table = db.createObjectStore(STORAGE_NAME, { keyPath: 'key' });
table.createIndex('value', 'value', { unique: false });
};
req.onsuccess = function(ev) {
req = undefined;
db = ev.target.result;
db.onerror = db.onabort = genericErrorHandler;
processPendings();
};
req.onerror = function() {
req.onerror = req.onblocked = function() {
req = undefined;
console.log(this.error);
processPendings();
pending = undefined;