Answer the question
In order to leave comments, you need to log in
How to access LocalStorage?
There is a site that, after loading, deletes the window.localStorage
, copying it to a local variable. More or less like this:
(function () {
let LS = window.localStorage;
delete window.localStorage;
})();
// ==UserScript==
// @name Get LS
// @run-at document-start
// @grant window.localStorage
// ==/UserScript==
(function() {
'use strict';
const LS = window.localStorage;
console.log(LS);
})();
Answer the question
In order to leave comments, you need to log in
You need to make sure that the script is executed immediately when the window is created, somewhere before the scripts start loading, at the very top.
There is also such a trick as creating an empty iframe and extracting the desired property from its global window object.
var iframe = document.createElement("iframe");
iframe .style.display = "none";
document.documentElement.appendChild(iframe);
var localStorage = iframe.contentWindow.localStorage;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question