mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 20:46:39 +02:00
Improved iFrame protection
This commit is contained in:
parent
92ff2ff5d4
commit
2da680bfcb
4 changed files with 162 additions and 34 deletions
44
lib/frame.js
44
lib/frame.js
|
@ -11,6 +11,7 @@
|
|||
const {check: originalCheck, checkStack: originalCheckStack} = require("./check");
|
||||
const {getWrapped} = require("./modifiedAPIFunctions");
|
||||
const extension = require("./extension");
|
||||
const iframeProtection = require("./iframeProtection");
|
||||
|
||||
const logging = require("./logging");
|
||||
const {error, warning, message, notice, verbose, setPrefix: setLogPrefix} = logging;
|
||||
|
@ -149,41 +150,16 @@
|
|||
{check, checkStack, ask: askWrapper, notify, prefs}
|
||||
);
|
||||
message("prepare to intercept (i)frames.");
|
||||
|
||||
[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){
|
||||
interceptWindow(window);
|
||||
}
|
||||
return window;
|
||||
}, window)
|
||||
|
||||
function interceptAllFrames(){
|
||||
const currentLength = window.length;
|
||||
for (let i = currentLength; i--;){
|
||||
if (!interceptedWindows.get(wrappedWindow[i])){
|
||||
interceptWindow(window[i]);
|
||||
}
|
||||
);
|
||||
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){
|
||||
interceptWindow(document.defaultView);
|
||||
}
|
||||
return document;
|
||||
}, window)
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
iframeProtection.protect(window, wrappedWindow, interceptWindow, interceptAllFrames);
|
||||
|
||||
const matchMediaDescriptor = Object.getOwnPropertyDescriptor(wrappedWindow, "matchMedia");
|
||||
const originalMatchMedia = matchMediaDescriptor.value;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue