diff --git a/app/scripts/lib/local-store.js b/app/scripts/lib/local-store.js index fbcba09cd7a9..8fde2e9111d7 100644 --- a/app/scripts/lib/local-store.js +++ b/app/scripts/lib/local-store.js @@ -49,7 +49,7 @@ module.exports = class ExtensionStore { const local = extension.storage.local return new Promise((resolve, reject) => { local.get(null, (/** @type {any} */ result) => { - const err = extension.runtime.lastError + const err = checkForError() if (err) { reject(err) } else { @@ -69,7 +69,7 @@ module.exports = class ExtensionStore { const local = extension.storage.local return new Promise((resolve, reject) => { local.set(obj, () => { - const err = extension.runtime.lastError + const err = checkForError() if (err) { reject(err) } else { @@ -88,3 +88,17 @@ module.exports = class ExtensionStore { function isEmpty (obj) { return Object.keys(obj).length === 0 } + +/** + * Returns an Error if extension.runtime.lastError is present + * this is a workaround for the non-standard error object thats used + * @returns {Error} + */ +function checkForError () { + const lastError = extension.runtime.lastError + if (!lastError) return + // if it quacks like an Error, its an Error + if (lastError.stack && lastError.message) return lastError + // repair incomplete error object (eg chromium v77) + return new Error(lastError.message) +}