Added test for settings loading

This commit is contained in:
kkapsner 2017-12-13 20:08:53 +01:00
parent bd48d1f39a
commit 67438d15ff
1 changed files with 58 additions and 4 deletions

View File

@ -3,17 +3,71 @@
<head>
<title>Test</title>
<script>
console.log("starting first fingerprint");
function fingerPrint(){
"use strict";var canvas = document.createElement("canvas");
canvas.setAttribute("width", 220);
canvas.setAttribute("height", 30);
var fp_text = "BrowserLeaks,com <canvas> 10";
var ctx = canvas.getContext("2d");
ctx.textBaseline = "top";
ctx.font = "14px 'Arial'";
ctx.textBaseline = "alphabetic";
ctx.fillStyle = "#f60";
ctx.fillRect(125, 1, 62, 20);
ctx.fillStyle = "#069";
ctx.fillText(fp_text, 2, 15);
ctx.fillStyle = "rgba(102, 204, 0, 07)";
ctx.fillText(fp_text, 4, 17);
return canvas.toDataURL();
}
function hash(url){
var buffer = new TextEncoder("utf-8").encode(url);
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("");
});
}
try {
var c = document.createElement("canvas").getContext("2d");
var firstFingerprint = fingerPrint();
}
catch (e){
console.log(e);
var c = false;
console.log(new Date(), e);
var firstFingerprint = false;
}
</script>
</head>
<body>
<script>
document.body.textContent = c? "context API not blocked": "context API blocked";
if (firstFingerprint){
document.body.textContent = "context API not blocked";
window.setTimeout(function(){
console.log("starting second fingerprint");
document.body.appendChild(document.createElement("br"));
secondFingerprint = fingerPrint();
if (firstFingerprint === secondFingerprint){
hash(firstFingerprint).then(function(hash){
document.body.appendChild(document.createTextNode("fingerprint consistent (" + firstFingerprint + ") -> good!"));
});
}
else {
Promise.all([hash(firstFingerprint), hash(secondFingerprint)]).then(function(hashes){
document.body.appendChild(document.createTextNode("fingerprint not consistent (" + hashes[0] + " != " + hashes[1] + ") -> very bad! (potential fingerprint leak)"));
document.body.style.backgroundColor = "red";
});
}
}, 500);
}
else {
document.body.textContent = "context API blocked";
}
</script>
</body></html>