mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 21:00:23 +01:00
detectionTest: check function code also in an iFrame
This commit is contained in:
parent
a7d02efd09
commit
0930928df3
@ -92,17 +92,35 @@ addTest("function length", function(log){
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
addTest("function code", function(log){
|
async function getIframe(){
|
||||||
|
"use strict";
|
||||||
|
return new Promise(function(resolve){
|
||||||
|
const length = window.length;
|
||||||
|
const iframe = document.createElement("iframe");
|
||||||
|
iframe.style.display = "none";
|
||||||
|
iframe.src = "?";
|
||||||
|
document.body.appendChild(iframe);
|
||||||
|
iframe.addEventListener("load", function(){
|
||||||
|
resolve(window[length]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
addTest("function code", async function(log){
|
||||||
"use strict";
|
"use strict";
|
||||||
let codeDetected = false;
|
let codeDetected = false;
|
||||||
|
const iframe = await getIframe();
|
||||||
function checkFunctionCode(func, expectedName){
|
function checkFunctionCode(func, expectedName){
|
||||||
log("checking", expectedName);
|
log("checking", expectedName);
|
||||||
if (!func.toString().match(
|
const reg = new RegExp("^\\s*function " + expectedName + "\\s*\\(\\)\\s*\\{\\s*\\[native code\\]\\s*\\}\\s*$");
|
||||||
new RegExp("^\\s*function " + expectedName + "\\s*\\(\\)\\s*\\{\\s*\\[native code\\]\\s*\\}\\s*$")
|
if (!func.toString().match(reg)){
|
||||||
)){
|
|
||||||
log("unexpected function code:", func.toString());
|
log("unexpected function code:", func.toString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
const iframeString = iframe.Function.prototype.toString.call(func);
|
||||||
|
if (!iframeString.match(reg)){
|
||||||
|
log("unexpected function code (iframe):", iframeString);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
log("canvas functions");
|
log("canvas functions");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user