Fix crashes when localStorage not available

As reported by @bimlas in https://github.com/Jermolene/TiddlyWiki5/issues/3945#issuecomment-496797809
fix-syncer
Jeremy Ruston 2019-05-29 09:01:11 +01:00
rodzic a8f70b08a8
commit 698733a4ad
2 zmienionych plików z 12 dodań i 9 usunięć

Wyświetl plik

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

Wyświetl plik

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