1
Fork 0

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
This commit is contained in:
Roy Wellington Ⅳ 2018-10-14 17:23:47 -07:00
parent 14f42a732f
commit d4e2dcaff1

View file

@ -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