From d82f8af4988e0a78810ec3ead2a748a974097bf0 Mon Sep 17 00:00:00 2001 From: Alexei Date: Fri, 31 May 2024 15:08:09 -0400 Subject: [PATCH] Handle storage.local.read() returning undefined --- src/js/storage.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/js/storage.js b/src/js/storage.js index 8dc5ba85b0..bd78a67573 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -84,8 +84,13 @@ function BadgerPen(callback) { // initialize from extension local storage chrome.storage.local.get(self.KEYS, function (store) { + let storage_err; + if (chrome.runtime.lastError) { + storage_err = chrome.runtime.lastError.message; + } + self.KEYS.forEach(key => { - if (utils.hasOwn(store, key)) { + if (store && utils.hasOwn(store, key)) { self[key] = new BadgerStorage(key, store[key]); } else { let storageObj = new BadgerStorage(key, {}); @@ -94,6 +99,14 @@ function BadgerPen(callback) { } }); + if (!store || storage_err) { + console.error("Error reading from extension storage:", storage_err); + if (!store) { + self.settings_map.setItem("showIntroPage", false); + self.settings_map.setItem("seenComic", true); + } + } + badger.initSettings(); if (!chrome.storage.managed) {