无法将 ES6 代理与 window.document 对象一起使用

Ris*_*hav 5 javascript es6-proxy

我已经编写了一些代码,这些代码应该document.cookie在发生这种情况时监视修改并打印到控制台。

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);
Run Code Online (Sandbox Code Playgroud)

但是,似乎文档对象实际上并没有改变。(它仍然是未经代理的版本)。因此,代理永远不会捕获对document.cookie

如果相反,我想在 上设置代理document.cookie,那似乎也是不可能的,因为无法捕获分配操作,而只能属性 get/set。

平台:Chrome 67.0.3396.79