1
0
Fork 0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-07-04 20:46:39 +02:00

test updates

This commit is contained in:
kkapsner 2019-12-16 19:27:28 +01:00
parent 717e1d3e3a
commit 0d0e3e30ec
16 changed files with 455 additions and 497 deletions

View file

@ -5,9 +5,9 @@ function draw(canvas){
canvas.setAttribute("width", 220);
canvas.setAttribute("height", 30);
var fp_text = "BrowserLeaks,com <canvas> 10";
const fp_text = "BrowserLeaks,com <canvas> 10";
var ctx = canvas.getContext("2d");
const ctx = canvas.getContext("2d");
ctx.textBaseline = "top";
ctx.font = "14px 'Arial'";
ctx.textBaseline = "alphabetic";
@ -24,33 +24,31 @@ function test(window){
"use strict";
// create window canvas
var canvas = document.createElement("canvas");
const canvas = document.createElement("canvas");
// draw image in window canvas
draw(canvas);
return window.HTMLCanvasElement.prototype.toDataURL.call(canvas);
}
function hash(string){
async function hash(string){
"use strict";
var buffer = new TextEncoder("utf-8").encode(string);
return crypto.subtle.digest("SHA-256", buffer).then(function(hash){
var chunks = [];
(new Uint32Array(hash)).forEach(function(num){
chunks.push(num.toString(16));
});
return chunks.map(function(chunk){
return "0".repeat(8 - chunk.length) + chunk;
}).join("");
const buffer = new TextEncoder("utf-8").encode(string);
const hash = await crypto.subtle.digest("SHA-256", buffer);
const chunks = [];
(new Uint32Array(hash)).forEach(function(num){
chunks.push(num.toString(16));
});
return chunks.map(function(chunk){
return "0".repeat(8 - chunk.length) + chunk;
}).join("");
}
var addLine = function(){
const addLine = function(){
"use strict";
var output = document.getElementById("results");
const output = document.getElementById("results");
return function(text){
var line = document.createElement("div");
const line = document.createElement("div");
line.textContent = text;
output.appendChild(line);
};
@ -59,13 +57,9 @@ var addLine = function(){
addLine("window name at start: " + window.name);
window.name = "CanvasBlocker CSP test";
addLine("window name after set: " + window.name);
hash(test(window)).then(function(hash){
(async function(){
"use strict";
addLine("canvas hash: " + hash);
return;
}).catch(function(error){
"use strict";
addLine("error while creating canvas hash: " + error);
});
const hashValue = await hash(test(window));
addLine("canvas hash: " + hashValue);
}());