1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-01-03 10:31:54 +01:00

Improved window intercepting.

This commit is contained in:
kkapsner 2017-10-10 21:11:50 +02:00
parent 68fb7730b9
commit e686b14106

View File

@ -81,10 +81,6 @@
var interceptedWindows = new WeakMap(); var interceptedWindows = new WeakMap();
function interceptWindow(window){ function interceptWindow(window){
if (!enabled || interceptedWindows.get(window)){
return false;
}
try { try {
var href = window.location.href; var href = window.location.href;
} }
@ -95,6 +91,10 @@
return false; return false;
} }
if (!enabled || interceptedWindows.get(getWrapped(window))){
return false;
}
message("intercepting window", window); message("intercepting window", window);
intercept( intercept(
{subject: window}, {subject: window},
@ -112,7 +112,9 @@
configureable: true, configureable: true,
get: exportFunction(function(){ get: exportFunction(function(){
var window = oldContentWindowGetter.call(this); var window = oldContentWindowGetter.call(this);
interceptWindow(window); if (window){
interceptWindow(window);
}
return window; return window;
}, window) }, window)
} }
@ -126,14 +128,16 @@
configureable: true, configureable: true,
get: exportFunction(function(){ get: exportFunction(function(){
var document = oldContentDocumentGetter.call(this); var document = oldContentDocumentGetter.call(this);
interceptWindow(document.defaultView); if (document){
interceptWindow(document.defaultView);
}
return document; return document;
}, window) }, window)
} }
); );
}); });
interceptedWindows.set(window, true); interceptedWindows.set(getWrapped(window), true);
return true; return true;
} }