From 1ccbbd8efef05ba11d387d3f4f09b8b6efe9f44b Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 17 Apr 2014 14:02:25 -0700 Subject: [PATCH] GUAC-278: Simply do not track connection history if localStorage unavailable. --- guacamole/src/main/webapp/scripts/history.js | 24 ++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/guacamole/src/main/webapp/scripts/history.js b/guacamole/src/main/webapp/scripts/history.js index 636d4be0d..5165e8df0 100644 --- a/guacamole/src/main/webapp/scripts/history.js +++ b/guacamole/src/main/webapp/scripts/history.js @@ -86,6 +86,10 @@ GuacamoleHistory = new (function() { */ this.update = function(id, thumbnail) { + /* Do nothing if localStorage not present */ + if (!localStorage) + return; + // Create updated entry var entry = new GuacamoleHistory.Entry( id, @@ -97,8 +101,11 @@ GuacamoleHistory = new (function() { history[id] = entry; truncate(); - // Save updated history - localStorage.setItem("GUAC_HISTORY", JSON.stringify(history)); + // Save updated history, ignore inability to use localStorage + try { + localStorage.setItem("GUAC_HISTORY", JSON.stringify(history)); + } + catch (ignore) {} }; @@ -107,9 +114,18 @@ GuacamoleHistory = new (function() { */ this.reload = function() { - // Get old and new for comparison + /* Do nothing if localStorage not present */ + if (!localStorage) + return; + + // Get old and new for comparison, ignore inability to use localStorage var old_history = history; - var new_history = JSON.parse(localStorage.getItem("GUAC_HISTORY") || "{}"); + try { + var new_history = JSON.parse(localStorage.getItem("GUAC_HISTORY") || "{}"); + } + catch (ignore) { + return; + } // Update history history = new_history;