diff --git a/test/domRectIFrame.html b/test/domRectIFrame.html new file mode 100644 index 0000000..443ad4d --- /dev/null +++ b/test/domRectIFrame.html @@ -0,0 +1,42 @@ + + + + + + + + +
+

https://browserleaks.com/rects

+Element.getClientRects (̿▀̿ ̿Ĺ̯̿̿▀̿ ̿)̄
+               +               +               +               +F i n g e r p r i n t i n g ? +
+ + \ No newline at end of file diff --git a/test/domRectTest.html b/test/domRectTest.html new file mode 100644 index 0000000..24b3a28 --- /dev/null +++ b/test/domRectTest.html @@ -0,0 +1,42 @@ + + + + DOMRect test + + + +

DOMRect test

+ +
+
+

+ Hash:
+ Data:
+ +
+
+ + + \ No newline at end of file diff --git a/test/domRectTest.js b/test/domRectTest.js new file mode 100644 index 0000000..b2d67fd --- /dev/null +++ b/test/domRectTest.js @@ -0,0 +1,68 @@ +(function(){ + "use strict"; + function byteArrayToHex(arrayBuffer){ + var chunks = []; + (new Uint32Array(arrayBuffer)).forEach(function(num){ + chunks.push(num.toString(16)); + }); + return chunks.map(function(chunk){ + return "0".repeat(8 - chunk.length) + chunk; + }).join(""); + } + + const container = document.getElementById("tests"); + const iframe = document.getElementById("iframe"); + const template = document.querySelector(".test"); + template.parentElement.removeChild(template); + + function getElements(){ + const doc = iframe.contentDocument; + + return Array.from(doc.querySelectorAll("*[id^=rect]")); + } + + function createTest(title, callback){ + const properties = ["x", "y", "width", "height", "top", "left", "right", "bottom"]; + function performTest(){ + const rects = getElements().map(callback); + const data = new Float64Array(rects.length * properties.length); + rects.forEach(function(rect, i){ + properties.forEach(function(property, j){ + data[i * properties.length + j] = rect[property]; + }); + }); + + crypto.subtle.digest("SHA-256", data) + .then(function(hash){ + output.querySelector(".hash").textContent = byteArrayToHex(hash); + }); + + output.querySelector(".data").innerHTML = "" + + rects.map(function(rect, i){ + return ""; + }).join("") + + "" + + properties.map(function(property){ + return "" + rects.map(function(rect, i){ + return ""; + }).join("") + ""; + }).join("") + + "
rect " + (i + 1) + "
" + property + "" + rect[property] + "
"; + + } + const output = template.cloneNode(true); + output.querySelector(".title").textContent = title; + output.querySelector("button").addEventListener("click", performTest); + + container.appendChild(output); + performTest(); + } + iframe.addEventListener("load", function(){ + createTest("getClientRects", function(element){ + return element.getClientRects()[0]; + }); + createTest("getBoundingClientRect", function(element){ + return element.getBoundingClientRect(); + }); + }); +}()); \ No newline at end of file