1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-23 05:10:27 +01:00

102 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-01-06 15:15:04 +01:00
/* globals testAPI, canvasAPI */
2017-08-13 23:44:31 +02:00
(function(){
2017-10-03 15:35:31 +02:00
"use strict";
2019-12-16 19:27:28 +01:00
async function show(container, {url, imageData, isPointInPath}){
const display = container.querySelector(".display");
2017-11-24 17:06:43 +01:00
display.src = url;
display.title = url;
2019-12-16 19:27:28 +01:00
const hashes = await Promise.all([
2020-01-06 15:15:04 +01:00
testAPI.hash(url),
testAPI.hash(imageData.data)
2019-12-16 19:27:28 +01:00
]);
container.querySelector(".hash").textContent =
2020-01-06 15:15:04 +01:00
hashes[0] + " / " +
hashes[1];
container.querySelector(".isPointInPath").textContent = isPointInPath;
2017-08-13 23:44:31 +02:00
}
2020-01-06 15:15:04 +01:00
function iframeTest(testNode){
const iframe = testNode.querySelector("iframe");
return canvasAPI.fingerprint(iframe.contentWindow);
}
const tests = {
top: function(){return canvasAPI.fingerprint();},
iframe: iframeTest,
iframe2: iframeTest,
iframe3: iframeTest,
iframe4: dynamicIframeTest1,
iframe5: dynamicIframeTest2,
iframe6: dynamicIframeTest3,
windowOpen: async function(testNode, initial){
if (initial){
return new Promise(function(resolve){
window.addEventListener("click", function windowOpenTest(){
window.removeEventListener("click", windowOpenTest);
const newWindow = window.open("/");
try{
resolve(canvasAPI.fingerprint(newWindow));
}
catch (error){
console.error(error);
}
newWindow.close();
});
});
2019-12-02 22:57:11 +01:00
}
2020-01-06 15:15:04 +01:00
else {
const newWindow = window.open("/");
const fingerprint = canvasAPI.fingerprint(newWindow);
newWindow.close();
return fingerprint;
2019-12-02 22:57:11 +01:00
}
2020-01-06 15:15:04 +01:00
}
};
Object.keys(tests).forEach(async function(testName){
const testNode = document.getElementById(testName);
const callback = tests[testName];
if (location.search !== "?notInitial"){
try {show(testNode, await callback(testNode, true));}
catch (error){console.error(testName, error);}
}
testNode.querySelector("button").addEventListener("click", async function(){
show(testNode, await callback(testNode));
2019-12-02 22:57:11 +01:00
});
});
2017-08-13 23:44:31 +02:00
}());
2019-05-22 23:46:56 +02:00
function dynamicIframeTest1(){
"use strict";
2019-12-16 19:27:28 +01:00
const length = frames.length;
const iframe = document.createElement("iframe");
2019-05-22 23:46:56 +02:00
document.body.appendChild(iframe);
2019-12-16 19:27:28 +01:00
const iframeWindow = frames[length];
2019-05-22 23:46:56 +02:00
document.body.removeChild(iframe);
2020-01-06 15:15:04 +01:00
return canvasAPI.fingerprint(iframeWindow);
2019-05-22 23:46:56 +02:00
}
function dynamicIframeTest2(){
"use strict";
2019-12-16 19:27:28 +01:00
const length = window.length;
const iframe = document.createElement("iframe");
2019-05-22 23:46:56 +02:00
document.body.appendChild(iframe);
2019-12-16 19:27:28 +01:00
const iframeWindow = window[length];
2019-05-22 23:46:56 +02:00
document.body.removeChild(iframe);
2020-01-06 15:15:04 +01:00
return canvasAPI.fingerprint(iframeWindow);
2019-05-22 23:46:56 +02:00
}
function dynamicIframeTest3(){
"use strict";
2019-12-16 19:27:28 +01:00
const length = window.length;
const div = document.createElement("div");
2019-05-22 23:46:56 +02:00
document.body.appendChild(div);
div.innerHTML = "<iframe></iframe>";
2019-12-16 19:27:28 +01:00
const iframeWindow = window[length];
2019-05-22 23:46:56 +02:00
document.body.removeChild(div);
2020-01-06 15:15:04 +01:00
return canvasAPI.fingerprint(iframeWindow);
2017-08-13 23:44:31 +02:00
}