Skip to content
Snippets Groups Projects
Unverified Commit 2c5391a1 authored by Walter Leibbrandt's avatar Walter Leibbrandt Committed by GitHub
Browse files

Factor out test for access to localStorage (#10533)

* Factor out test for access to localStorage

This allows code that uses localStorage to test against
`window.hasLocalStorage`, in stead of handling exceptions generated when
access to localStorage is denied.

* Move check for localStorage to metabase/lib/dom
parent 83dcd439
No related branches found
No related tags found
No related merge requests found
import { HAS_LOCAL_STORAGE } from "metabase/lib/dom";
let debug;
if (
typeof window === "object" &&
((window.location && window.location.hash === "#debug") ||
(window.localStorage && window.localStorage.getItem("debug")))
(HAS_LOCAL_STORAGE && window.localStorage.getItem("debug")))
) {
debug = true;
} else {
......
......@@ -26,6 +26,18 @@ export const IFRAMED_IN_SELF = (function() {
}
})();
// check if we have access to localStorage to avoid handling "access denied"
// exceptions
export const HAS_LOCAL_STORAGE = (function() {
try {
window.localStorage; // This will trigger an exception if access is denied.
return true;
} catch (e) {
console.warn("localStorage not available:", e);
return false;
}
})();
export function isObscured(element, offset) {
if (!document.elementFromPoint) {
return false;
......
import React from "react";
import { HAS_LOCAL_STORAGE } from "metabase/lib/dom";
// If enabled this monkeypatches `t` and `jt` to return blacked out
// strings/elements to assist in finding untranslated strings.
//
......@@ -52,6 +54,6 @@ export function enableTranslatedStringReplacement() {
};
}
if (window.localStorage && window.localStorage["metabase-i18n-debug"]) {
if (HAS_LOCAL_STORAGE && window.localStorage["metabase-i18n-debug"]) {
enableTranslatedStringReplacement();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment