Skip to content

Commit

Permalink
try...catch localStorage access (fix #218)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 5, 2017
1 parent 63d3583 commit ee840a4
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/devtools/storage.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
// If the users blocks 3rd party cookies and storage,
// localStorage will throw.

export default {
get (key) {
return JSON.parse(localStorage.getItem(key))
try {
return JSON.parse(localStorage.getItem(key))
} catch (e) {}
},
set (key, val) {
localStorage.setItem(key, JSON.stringify(val))
try {
localStorage.setItem(key, JSON.stringify(val))
} catch (e) {}
},
remove (key) {
localStorage.removeItem(key)
try {
localStorage.removeItem(key)
} catch (e) {}
},
clear () {
localStorage.clear()
try {
localStorage.clear()
} catch (e) {}
}
}

0 comments on commit ee840a4

Please sign in to comment.