web: behaviour: catch localStorage errors
If bounding the jobs to 1000 is still not enough, a safe fallback is to
catch the error if we fail to write. Users won't get the full benefits
of caching, but at least they'll be able to use the page.
@@ -115,7 +115,11 @@ app.ports.saveToLocalStorage.subscribe(function(params) {
return;
}
const [key, value] = params;
+ try {
localStorage.setItem(key, JSON.stringify(value));
+ } catch(err) {
+ console.error(err);
+ }
});
app.ports.saveToSessionStorage.subscribe(function(params) {
@@ -123,7 +127,11 @@ app.ports.saveToSessionStorage.subscribe(function(params) {
return;
}
const [key, value] = params;
+ try {
sessionStorage.setItem(key, JSON.stringify(value));
+ } catch(err) {
+ console.error(err);
+ }
});
app.ports.loadFromLocalStorage.subscribe(function(key) {
