From 8fabcabebbd910c5ec08e1fc07d1851b0605aee6 Mon Sep 17 00:00:00 2001 From: "jeremy@jermolene.com" Date: Sat, 21 May 2022 15:36:23 +0100 Subject: [PATCH] Browserstorage plugin: don't crash if local storage not available Fix #6701 --- plugins/tiddlywiki/browser-storage/startup.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/tiddlywiki/browser-storage/startup.js b/plugins/tiddlywiki/browser-storage/startup.js index 0f93de13b..33989e8a7 100644 --- a/plugins/tiddlywiki/browser-storage/startup.js +++ b/plugins/tiddlywiki/browser-storage/startup.js @@ -115,13 +115,15 @@ function saveTiddlerToLocalStorage(title,options) { function clearLocalStorage() { var url = window.location.pathname, log = []; - // Step through each browsder storage item - for(var index=window.localStorage.length - 1; index>=0; index--) { - var key = window.localStorage.key(index), - parts = key.split("#"); - // Delete it if it's ours - if(parts[0] === "tw5" && parts[1] === url) { - window.localStorage.removeItem(key); + // Step through each browser storage item + if(window.localStorage) { + for(var index=window.localStorage.length - 1; index>=0; index--) { + var key = window.localStorage.key(index), + parts = key.split("#"); + // Delete it if it is ours + if(parts[0] === "tw5" && parts[1] === url) { + window.localStorage.removeItem(key); + } } } }