Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
local-storage-debug-script.js
Object.defineProperty(window, 'localStorage', {
configurable: true,
enumerable: true,
value: new Proxy(localStorage, {
set: function (ls, prop, value) {
console.log(`direct assignment: ${prop} = ${value}`);
debugger;
ls[prop] = value;
return true;
},
get: function(ls, prop) {
if (prop === 'setItem' || prop === 'getItem') {
console.log(prop + ' called');
debugger;
return ls[prop].bind(ls);
} else if (typeof ls[prop] === 'function') {
console.log(prop + ' called');
return ls[prop].bind(ls);
} else {
console.log('Property Retrieved: ' + prop);
console.log('Property Retrieved Value: ' + ls[prop]);
debugger;
return ls[prop];
}
}
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment