Created
November 30, 2018 17:22
-
-
Save frederickding/16e02b110e690fb8cbbaf725448b3a61 to your computer and use it in GitHub Desktop.
local-storage-debug-script.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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