JSFiddle - React, Tailwind, and code Playground
by sperske
JavaScript
const key = "Grammarly.localStorage.access";
if ("localStorage" in window) {
if (localStorage.getItem(key)) {
alert("LocalStorage has persisted value");
} else {
try {
const expected = Math.random().toString();
window.localStorage.setItem(key, expected);
if (window.localStorage.getItem(key) === expected) {
alert("LocalStorage is useable!");
} else {
throw new Error("Unable to persist");
}
} catch (e) {
console.log(e)
alert("LocalStorage not useable")
}
}
} else {
alert('LocalStorage Not available')
}