1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-01-03 02:21:53 +01:00

Improved performance for protected canvas part "input"

Fixes #517
This commit is contained in:
kkapsner 2021-01-03 17:36:40 +01:00
parent fcbc622cef
commit b4a744660b
2 changed files with 13 additions and 3 deletions

View File

@ -226,17 +226,26 @@
if (!this || canvasSizeShouldBeFaked(this.canvas, prefs)){
notify("fakedInput");
let oldImageData;
let x, y, width, height;
const border = 4;
try {
// "this" is not trustable - it may be not a context
oldImageData = getImageData(window, this).imageData;
const measurement = window.CanvasRenderingContext2D.prototype.measureText.call(this, args[0]);
width = Math.ceil(measurement.actualBoundingBoxRight + measurement.actualBoundingBoxLeft) + border;
height = Math.ceil(measurement.actualBoundingBoxDescent + measurement.actualBoundingBoxAscent) + border;
x = Math.max(0, args[1] - width);
y = Math.max(0, args[2] - height);
width = Math.min(3 * width, this.canvas.width - x);
height = Math.min(3 * height, this.canvas.height - y);
oldImageData = window.CanvasRenderingContext2D.prototype.getImageData.call(this, x, y, width, height);
}
catch (error){
// nothing to do here
}
// if "this" is not a correct context the next line will throw an error
const ret = original.call(this, ...args);
const newImageData = getImageData(window, this).imageData;
this.putImageData(randomMixImageData(window, oldImageData, newImageData), 0, 0);
const newImageData = window.CanvasRenderingContext2D.prototype.getImageData.call(this, x, y, width, height);
this.putImageData(randomMixImageData(window, oldImageData, newImageData), x, y);
return ret;
}
else {

View File

@ -4,6 +4,7 @@ Version 1.5:
new features:
- added {empty}, {false} and {undefined} to webGL preference parameters (i.e. VENDOR, RENDERER, UNMASKED_VENDOR_WEBGL and UNMASKED_RENDERER_WEBGL)
- improved performance for protected canvas part "input"
fixes:
- protection of DOM manipulations on unloaded windows may break websites