Created
August 30, 2024 19:48
-
-
Save Igloczek/19d7e1f441761da76004422970f3e569 to your computer and use it in GitHub Desktop.
A way to unfuck the Chrome Storage API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const storage = { | |
async get(key) { | |
return new Promise((resolve, reject) => { | |
chrome.storage.local.get(key, (result) => { | |
if (chrome.runtime.lastError) { | |
return reject(chrome.runtime.lastError) | |
} | |
resolve(result[key]) | |
}) | |
}) | |
}, | |
async set(key, value) { | |
return new Promise((resolve, reject) => { | |
chrome.storage.local.set({ [key]: value }, () => { | |
if (chrome.runtime.lastError) { | |
return reject(chrome.runtime.lastError) | |
} | |
resolve() | |
}) | |
}) | |
}, | |
async remove(key) { | |
return new Promise((resolve, reject) => { | |
chrome.storage.local.remove(key, () => { | |
if (chrome.runtime.lastError) { | |
return reject(chrome.runtime.lastError) | |
} | |
resolve() | |
}) | |
}) | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment