in workbox-v4.3.1/workbox-core.dev.js [1043:1083]
async open() {
if (this._db) return;
this._db = await new Promise((resolve, reject) => {
// This flag is flipped to true if the timeout callback runs prior
// to the request failing or succeeding. Note: we use a timeout instead
// of an onblocked handler since there are cases where onblocked will
// never never run. A timeout better handles all possible scenarios:
// https://github.com/w3c/IndexedDB/issues/223
let openRequestTimedOut = false;
setTimeout(() => {
openRequestTimedOut = true;
reject(new Error('The open request was blocked and timed out'));
}, this.OPEN_TIMEOUT);
const openRequest = indexedDB.open(this._name, this._version);
openRequest.onerror = () => reject(openRequest.error);
openRequest.onupgradeneeded = evt => {
if (openRequestTimedOut) {
openRequest.transaction.abort();
evt.target.result.close();
} else if (this._onupgradeneeded) {
this._onupgradeneeded(evt);
}
};
openRequest.onsuccess = ({
target
}) => {
const db = target.result;
if (openRequestTimedOut) {
db.close();
} else {
db.onversionchange = this._onversionchange.bind(this);
resolve(db);
}
};
});
return this;
}