I have written some code that is supposed to watch for modifications to document.cookie
and print to console whenever that happens.
var handler = {
set: function(target, property, value) {
console.log("in proxy");
if (property === "cookie") {
console.log(`cookie is being modified with val ${value}`);
}
return Reflect.set(...arguments);
}
}
window.document = new Proxy(document, handler);
However, it seems that the document object isn't actually changed. (It remains the unproxied version). Therefore, the proxy never catches modifications to document.cookie
.
If instead, I want to set a proxy on document.cookie
, that also seems impossible because there is no way to trap the assignment operation, but instead only property get/set.
Platform: Chrome 67.0.3396.79