write-only option
Mirroring the approach taken by mozilla bug 967895 might be interesting as a extra option between allowing or blocking all access to Canvas.
Their approach is to allow pages to write to canvas, but to return a completely white image when getImageData() is called, unless given permission.
Bug967895's implementation changes the Firefox source code, but perhaps a javascript only solution is possible similar to your current blocking code by overriding the regular implementation when permission is denied or by leaving it as is if access is allowed.
Something like this to override getImageData()
CanvasRenderingContext2D.prototype.getImageData = function(x, y, w, h) {
var imgdata = new ImageData(w, h);
var i=w*h*4; // 4 bytes per pixel for RGBA
while(i) {
imgdata.data[i--] = 0xFF;
}
return imgdata;
};
Great Idea. I will add an option in the blockingMode.
But if someone uses it she/he must be aware that this is a fingerprint that the Add-On is used.
But if someone uses it she/he must be aware that this is a fingerprint that the Add-On is used.
Or that Tor Browser is used (that's where Bug967895's patch comes from). Possibly they get a little less info about the platform the browser runs on though.
Note that ImageData's default data is all zero (so black instead of white), so if you don't replace the data with 255 or 0xFF it will be identifiable as CanvasBlocker (and not Tor Browser).
Maybe the best way would be to fill it with random values.
But getImageData is not the only function that has to be altered. There are also .toBlob(), .toDataURL() and .mozGetAsFile() of the canvas itself.
I tried to randomise them - check out the fakeImageDataApproach branch.
Right! I had absolutely overlooked toBlob(), toDataURL() and mozGetAsFile(). Good catch! :)
Also a good idea to use random values; No lumping in with Tor Browser and harder to identify as fake data.
It's will always be detectable.
I merged the fake options to the master so it will be in the next release.