Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
tampermonkey userscripts for cookies and localStorage
// ==UserScript==
// @name debug localStorage.setItem()
// @namespace https://josepedrodias.com/
// @version 0.1
// @description yada yada
// @author jose.pedro.dias@gmail.com
// @match https://putyoursitehere/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
// based on https://gist.github.com/mynameislau/b7eabfcdc0a17ac41cdc0b974f94d807
const ignores = [
'test'
];
Object.defineProperty(window, 'localStorage', {
configurable: true,
enumerable: true,
value: new Proxy(localStorage, {
set: function (ls, prop, value) {
if (ignores.indexOf(prop) === -1) {
//console.error(`LS direct assignment of ${prop}`);
debugger;
}
ls[prop] = value;
return true;
},
get: function (ls, prop) {
if (prop !== 'setItem') {
if (typeof ls[prop] === 'function') {
return ls[prop].bind(ls);
} else {
return ls[prop];
}
}
return (...args) => {
const key = args[0];
if (ignores.indexOf(key) === -1) {
//console.error(`LS setItem(${key})`);
debugger;
}
ls.setItem.apply(ls, args);
};
},
}),
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.