Skip to content

Instantly share code, notes, and snippets.

@tankred
Created November 28, 2014 21:23
Show Gist options
  • Save tankred/9bc377f3ed3415412178 to your computer and use it in GitHub Desktop.
Save tankred/9bc377f3ed3415412178 to your computer and use it in GitHub Desktop.
browserleaks
<canvas id="drawing"></canvas>
var canvas = document.getElementById("drawing");
var ctx = canvas.getContext("2d");
// text with lowercase/uppercase/punctuation symbols
var txt = "BrowserLeaks,com <canvas> 1.0";
ctx.textBaseline = "top";
// the most common type
ctx.font = "14px 'Arial'";
ctx.textBaseline = "alphabetic";
ctx.fillStyle = "#f60";
ctx.fillRect(125,1,62,20);
// some tricks for color mixing
ctx.fillStyle = "#069";
ctx.fillText(txt, 2, 15);
ctx.fillStyle = "rgba(102, 204, 0, 0.7)";
ctx.fillText(txt, 4, 17);
// code is simple but we must provide some conversion functions
// it is still less and faster than md5
function bin2hex (s) {
// ... bin-to-hex conversion code ...
}
if (typeof window.atob == "undefined") {
function atob(a) {
// IE9 still has not atob() function (base64-to-binary)
// ... you must put some replacement here ...
}
}
var b64 = canvas.toDataURL.replace("data:image/png;base64,","");
var bin = atob(b64);
// crc32 takes only 4 bytes and placed from 16 to 12 byte from the end of file
var crc = bin2hex(bin.slice(-16,-12));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment