Skip to content

Commit

Permalink
Merge pull request #192 from ecency/191-securityerror-failed-to-read-…
Browse files Browse the repository at this point in the history
…the-localstorage-property-from-window-access-is-denied-for-this-document

Wrap with try catch local storage accessing
  • Loading branch information
feruzm authored Nov 26, 2024
2 parents 4af992a + a3945d0 commit ccd2575
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/utils/local-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ export function get(k: string, def: any = null): any {
return null;
}

const key = `${PREFIX}_${k}`;
const val = localStorage.getItem(key);
return val ? JSON.parse(val) : def;
try {
const key = `${PREFIX}_${k}`;
const val = localStorage.getItem(key);
return val ? JSON.parse(val) : def;
} catch (e) {
return def;
}
}

export function set(k: string, v: any): void {
Expand Down

0 comments on commit ccd2575

Please sign in to comment.