Skip to content

Instantly share code, notes, and snippets.

@jvatic
Last active August 29, 2015 14:04
Show Gist options
  • Save jvatic/07a60099b4821e971c2b to your computer and use it in GitHub Desktop.
Save jvatic/07a60099b4821e971c2b to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Canvas Tracking Blocker
// @namespace ctb
// @description Monkey patches toDataURL for canvas to make it non-deterministic
// @include *
// @version 1
// @grant none
// @run-at document-start
// ==/UserScript==
var toDataURL = HTMLCanvasElement.prototype.toDataURL;
HTMLCanvasElement.prototype.toDataURL = function () {
if ( !this.__obstructed ) {
var ctx = this.getContext("2d");
ctx.fillStyle = "rgba(255, 255, 255, 0.1)";
ctx.fillRect(Math.random(1), Math.random(1), Math.random(0.2), Math.random(0.2));
this.__obstructed = true;
}
return toDataURL.apply(this, arguments);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment