1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +00:00

Fix crashes when localStorage not available

As reported by @bimlas in https://github.com/Jermolene/TiddlyWiki5/issues/3945#issuecomment-496797809
This commit is contained in:
Jeremy Ruston 2019-05-29 09:01:11 +01:00
parent a8f70b08a8
commit 698733a4ad
2 changed files with 12 additions and 9 deletions

View File

@ -27,6 +27,12 @@ if(Object.prototype.hasOwnProperty.call($tw.hooks.names,hookName)) {
function hookBootTiddlersLoaded() { function hookBootTiddlersLoaded() {
var url = window.location.pathname, var url = window.location.pathname,
log = []; log = [];
// Check that browser storage is available
try {
window.localStorage;
} catch(e) {
return;
}
// Step through each browsder storage item // Step through each browsder storage item
for(var index=0; index<window.localStorage.length; index++) { for(var index=0; index<window.localStorage.length; index++) {
var key = window.localStorage.key(index), var key = window.localStorage.key(index),

View File

@ -181,15 +181,12 @@ function saveScrollPosition() {
} }
function restoreScrollPosition() { function restoreScrollPosition() {
var str = window.localStorage.getItem(LOCAL_STORAGE_KEY_PREFIX + window.location.pathname), var json;
json;
if(str) {
try { try {
json = JSON.parse(str); json = JSON.parse(window.localStorage.getItem(LOCAL_STORAGE_KEY_PREFIX + window.location.pathname));
} catch(e) { } catch(e) {
// Ignore errors // Ignore errors
}; };
}
return json; return json;
} }