Skip to content

Instantly share code, notes, and snippets.

@Igloczek
Created August 30, 2024 19:48
Show Gist options
  • Save Igloczek/19d7e1f441761da76004422970f3e569 to your computer and use it in GitHub Desktop.
Save Igloczek/19d7e1f441761da76004422970f3e569 to your computer and use it in GitHub Desktop.
A way to unfuck the Chrome Storage API
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