fix: protect stale extension context

App would crash on storage manipulation when context is stale
This commit is contained in:
EnixCoda 2019-12-01 23:03:07 +08:00
parent f54f2ea440
commit effaca1f2c
No known key found for this signature in database
GPG key ID: 0C1A07377913A1DD

View file

@ -1,9 +1,13 @@
const localStorage = browser.storage.local
export function get(mapping: string[] | null): Promise<any> {
return localStorage.get(mapping || undefined)
export function get(mapping: string[] | null): Promise<any> | any {
try {
return localStorage.get(mapping || undefined)
} catch (err) {}
}
export function set(value: any): Promise<void> {
return localStorage.set(value)
export function set(value: any): Promise<void> | void {
try {
return localStorage.set(value)
} catch (err) {}
}