Skip to content

Commit

Permalink
Handle storage.local.read() returning undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostwords committed May 31, 2024
1 parent 8d852ae commit d82f8af
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {});
Expand All @@ -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) {
Expand Down

0 comments on commit d82f8af

Please sign in to comment.