Skip to content

Instantly share code, notes, and snippets.

@cmbuckley
Last active November 21, 2018 12:56
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 cmbuckley/855ef9b7a202472ad77ca289afa71744 to your computer and use it in GitHub Desktop.
Save cmbuckley/855ef9b7a202472ad77ca289afa71744 to your computer and use it in GitHub Desktop.
JavaScript Cookie Trapper
// Use to detect calls to document.cookie="xxx"
(function (){
var s = document.__lookupSetter__('cookie').bind(document),
g = document.__lookupGetter__('cookie').bind(document);
Object.defineProperty(document, 'cookie', {
get() {
return g();
},
set(n) {
console.error('Setting cookie:', n);
s(n);
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment