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() {
|
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),
|
||||||
|
@ -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;
|
try {
|
||||||
if(str) {
|
json = JSON.parse(window.localStorage.getItem(LOCAL_STORAGE_KEY_PREFIX + window.location.pathname));
|
||||||
try {
|
} catch(e) {
|
||||||
json = JSON.parse(str);
|
// Ignore errors
|
||||||
} catch(e) {
|
};
|
||||||
// Ignore errors
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user