Posting this as I was struggling with this question as well and finally found a solution.
This works in the Firefox console only as far as I can tell...
- Set a breakpoint on the very first line of javascript that you know runs on your page after a refresh (before any cookie is set).
- Then clear your cache and cookies.
- Paste the below code snippet into your console in Firefox.
- Remove the breakpoint and resume script execution.
You should see the stack trace for each cookie being created in the console!
origDescriptor = Object.getOwnPropertyDescriptor(HTMLDocument.prototype, 'cookie'); // add cookie property to HTMLDocument constructor
Object.defineProperty(document, 'cookie', {
get() {
return origDescriptor.get.call(this);
},
set(value) {
console.log("%c Cookie is :" + value, "background: #ffffff; color: #000000");
console.trace();
// debugger;
return origDescriptor.set.call(this, value);
},
enumerable: true,
configurable: true
});
I have to give credit to fflorent for this code he posted in another topic - thanks!
arguments.callee.caller.name
, you can get a pretty good idea of where the set was initiated. i haven't tried this for cookies, but ive used it to debug other native "APIs". aside: are cookies an api? why isn't there a nice cookie api yet? – Tyner