Skip to content

Instantly share code, notes, and snippets.

@frederickding
Created November 30, 2018 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frederickding/16e02b110e690fb8cbbaf725448b3a61 to your computer and use it in GitHub Desktop.
Save frederickding/16e02b110e690fb8cbbaf725448b3a61 to your computer and use it in GitHub Desktop.
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