1
0
Fork 0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-07-04 20:46:39 +02:00

Added window.open protection

This commit is contained in:
kkapsner 2019-12-02 22:57:11 +01:00
parent a181780020
commit 762367a87b
5 changed files with 55 additions and 0 deletions

View file

@ -262,6 +262,32 @@
);
}
function protectWindowOpen({window, wrappedWindow, changeProperty, singleCallback}){
const windowOpenDescriptor = Object.getOwnPropertyDescriptor(
wrappedWindow,
"open"
);
const windowOpen = windowOpenDescriptor.value;
const getDocument = Object.getOwnPropertyDescriptor(
window,
"document"
).get;
changeProperty(
wrappedWindow,
"open", "value", exportFunction(function open(){
const newWindow = arguments.length?
windowOpen.apply(this, window.Array.from(arguments)):
windowOpen.call(this);
if (newWindow){
// if we use windowOpen from the normal window we see some SOP errors
// BUT we need the unwrapped window...
singleCallback(getDocument.call(newWindow).defaultView);
}
return newWindow;
}, window)
);
}
scope.protect = function protect(window, wrappedWindow, singleCallback, allCallback){
const changeProperty = createChangeProperty(window);
@ -280,5 +306,7 @@
// MutationObserver does not trigger fast enough when document.write is used
protectDocumentWrite(api);
protectWindowOpen(api);
};
}());