From d4e2dcaff1bb957f41384e9e6a0dbb830dffe09c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roy=20Wellington=20=E2=85=A3?= Date: Sun, 14 Oct 2018 17:23:47 -0700 Subject: [PATCH] Detect if access to localStorage is forbidden by the user's browser If the user's cookie/persistent storage setting forbid access to localStorage, catch the exception and abort the access. Currently, attempting to use the expand/contract links at the top of the page for structs/consts/etc. fails due to an unhandled error while accessing localStorage, if such access is forbidden, as the exception from the failed access propagates all the way out, interrupting the expand/contract. Instead, I would like to degrade gracefully; the access won't happen (the collapse/expand state won't get persisted) but the actual expanding/contracting of the item will go on to succeed. Fixes #55079 --- src/librustdoc/html/static/storage.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/librustdoc/html/static/storage.js b/src/librustdoc/html/static/storage.js index 4ef8349fa9ce..9dc78f7beb61 100644 --- a/src/librustdoc/html/static/storage.js +++ b/src/librustdoc/html/static/storage.js @@ -28,6 +28,12 @@ function onEach(arr, func) { function updateLocalStorage(name, value) { if (typeof(Storage) !== "undefined") { + try { + window.localStorage; + } catch(err) { + // Storage is supported, but browser preferences deny access to it. + return; + } localStorage[name] = value; } else { // No Web Storage support so we do nothing