mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 03:57:21 +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:
parent
a8f70b08a8
commit
698733a4ad
@ -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),
|
||||
|
@ -181,15 +181,12 @@ function saveScrollPosition() {
|
||||
}
|
||||
|
||||
function restoreScrollPosition() {
|
||||
var str = window.localStorage.getItem(LOCAL_STORAGE_KEY_PREFIX + window.location.pathname),
|
||||
json;
|
||||
if(str) {
|
||||
var json;
|
||||
try {
|
||||
json = JSON.parse(str);
|
||||
json = JSON.parse(window.localStorage.getItem(LOCAL_STORAGE_KEY_PREFIX + window.location.pathname));
|
||||
} catch(e) {
|
||||
// Ignore errors
|
||||
};
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user