MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / storageAvailable

Function storageAvailable

console/src/utils/storageAvailable.tsx:13–40  ·  view source on GitHub ↗
(
  type: "localStorage" | "sessionStorage",
)

Source from the content-addressed store, hash-verified

11// Storage can be disabled in private mode or full, for example
12// From https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API
13export default function storageAvailable(
14 type: "localStorage" | "sessionStorage",
15) {
16 let storage;
17 try {
18 storage = window[type];
19 const x = "__storage_test__";
20 storage.setItem(x, x);
21 storage.removeItem(x);
22 return true;
23 } catch (e) {
24 return (
25 e instanceof DOMException &&
26 // everything except Firefox
27 (e.code === 22 ||
28 // Firefox
29 e.code === 1014 ||
30 // test name field too, because code might not be present
31 // everything except Firefox
32 e.name === "QuotaExceededError" ||
33 // Firefox
34 e.name === "NS_ERROR_DOM_QUOTA_REACHED") &&
35 // acknowledge QuotaExceededError only if there's something already stored
36 storage &&
37 storage.length !== 0
38 );
39 }
40}

Callers 10

cloudRegions.tsFile · 0.85
environments.tsFile · 0.85
getCacheFunction · 0.85
appendToCacheFunction · 0.85
useTimePeriodMinutesFunction · 0.85
useLocalStorageFunction · 0.85
getCurrentStackFunction · 0.85
setCurrentStackFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected