mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 20:46:39 +02:00
parent
ef1c45efab
commit
c3d4a1901c
3 changed files with 45 additions and 32 deletions
|
@ -11,43 +11,52 @@
|
|||
else {
|
||||
scope = require.register("./iframeProtection", {});
|
||||
}
|
||||
const {getWrapped} = require("./modifiedAPIFunctions");
|
||||
|
||||
scope.protect = function protect(window, wrappedWindow, singleCallback, allCallback){
|
||||
|
||||
[window.HTMLIFrameElement, window.HTMLFrameElement].forEach(function(constructor){
|
||||
var oldContentWindowGetter = constructor.prototype.__lookupGetter__("contentWindow");
|
||||
Object.defineProperty(
|
||||
getWrapped(constructor.prototype),
|
||||
"contentWindow",
|
||||
{
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
get: exportFunction(function(){
|
||||
var window = oldContentWindowGetter.call(this);
|
||||
if (window){
|
||||
singleCallback(window);
|
||||
}
|
||||
return window;
|
||||
}, window)
|
||||
}
|
||||
["HTMLIFrameElement", "HTMLFrameElement"].forEach(function(constructorName){
|
||||
const constructor = window[constructorName];
|
||||
const wrappedConstructor = wrappedWindow[constructorName];
|
||||
|
||||
const contentWindowDescriptor = Object.getOwnPropertyDescriptor(
|
||||
constructor.prototype,
|
||||
"contentWindow"
|
||||
);
|
||||
var oldContentDocumentGetter = constructor.prototype.__lookupGetter__("contentDocument");
|
||||
Object.defineProperty(
|
||||
getWrapped(constructor.prototype),
|
||||
"contentDocument",
|
||||
{
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
get: exportFunction(function(){
|
||||
var document = oldContentDocumentGetter.call(this);
|
||||
if (document){
|
||||
singleCallback(document.defaultView);
|
||||
}
|
||||
return document;
|
||||
}, window)
|
||||
const originalContentWindowGetter = contentWindowDescriptor.get;
|
||||
const contentWindowTemp = {
|
||||
get contentWindow(){
|
||||
var window = originalContentWindowGetter.call(this);
|
||||
if (window){
|
||||
singleCallback(window);
|
||||
}
|
||||
return window;
|
||||
}
|
||||
};
|
||||
contentWindowDescriptor.get = exportFunction(
|
||||
Object.getOwnPropertyDescriptor(contentWindowTemp, "contentWindow").get,
|
||||
window
|
||||
);
|
||||
Object.defineProperty(wrappedConstructor.prototype, "contentWindow", contentWindowDescriptor);
|
||||
|
||||
const contentDocumentDescriptor = Object.getOwnPropertyDescriptor(
|
||||
constructor.prototype,
|
||||
"contentDocument"
|
||||
);
|
||||
const originalContentDocumentGetter = contentDocumentDescriptor.get;
|
||||
const contentDocumentTemp = {
|
||||
get contentDocument(){
|
||||
var document = originalContentDocumentGetter.call(this);
|
||||
if (document){
|
||||
singleCallback(document.defaultView);
|
||||
}
|
||||
return document;
|
||||
}
|
||||
};
|
||||
contentDocumentDescriptor.get = exportFunction(
|
||||
Object.getOwnPropertyDescriptor(contentDocumentTemp, "contentDocument").get,
|
||||
window
|
||||
);
|
||||
Object.defineProperty(wrappedConstructor.prototype, "contentDocument", contentDocumentDescriptor);
|
||||
});
|
||||
[
|
||||
// useless as length could be obtained before the iframe is created and window.frames === window
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue