Skip to content

Commit d4e2dca

Browse files
committed
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
1 parent 14f42a7 commit d4e2dca

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/librustdoc/html/static/storage.js

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ function onEach(arr, func) {
2828

2929
function updateLocalStorage(name, value) {
3030
if (typeof(Storage) !== "undefined") {
31+
try {
32+
window.localStorage;
33+
} catch(err) {
34+
// Storage is supported, but browser preferences deny access to it.
35+
return;
36+
}
3137
localStorage[name] = value;
3238
} else {
3339
// No Web Storage support so we do nothing

0 commit comments

Comments
 (0)