I need to Proxy a window object opened with window.open.
So far as I understand it (which is not well), the trivial "handler" here should effectively be the identity operation, passing thru property accesses unmodified:
let origOpen = window.open;
window.open = function(url) {
let openedWindow = origOpen.apply(this, arguments);
let handler = {
get(target, prop, receiver) {
return Reflect.get(...arguments);
}
};
let wrappedWindow = new Proxy(openedWindow, handler);
return wrappedWindow;
};
let wi = window.open("https://example.net/");
console.log(wi.closed);
However, when this script reaches the line which tries to log wi.closed, it throws the following exception:
Uncaught TypeError: 'get closed' called on an object that does not implement interface Window.
(Using Firefox ESR 115.)
Reflect.get(target, prop, target)instead ofReflect.get(target, prop, receiver)for builtin getters. You'd have the same problem for methods though