(function () {
'use strict';
var UNMASKED_VENDOR_WEBGL = 0x9245;
var UNMASKED_RENDERER_WEBGL = 0x9246;
var VENDOR = 0x1f00;
var RENDERER = 0x1f01;
var FAKE_UNMASKED_VENDOR = 'Google Inc. (Intel)';
var FAKE_UNMASKED_RENDERER = 'ANGLE (Intel, Intel(R) Iris(R) Xe Graphics (0x00004626) Direct3D11 vs_5_0 ps_5_0, D3D11)';
var FAKE_VENDOR = 'WebKit';
var FAKE_RENDERER = 'WebKit WebGL';
function wrapFunction(target, hook) {
return new Proxy(target, {
apply: function (_target, thisArg, args) {
return hook(thisArg, args, function (self) {
return Reflect.apply(target, self || thisArg, args);
});
},
});
}
function hookGetParameter(proto) {
if (!proto || typeof proto.getParameter !== 'function') {
return;
}
proto.getParameter = wrapFunction(proto.getParameter, function (_self, args, orig) {
switch (args[0]) {
case UNMASKED_VENDOR_WEBGL:
return FAKE_UNMASKED_VENDOR;
case UNMASKED_RENDERER_WEBGL:
return FAKE_UNMASKED_RENDERER;
case VENDOR:
return FAKE_VENDOR;
case RENDERER:
return FAKE_RENDERER;
default:
return orig();
}
});
}
if (typeof WebGLRenderingContext !== 'undefined') {
hookGetParameter(WebGLRenderingContext.prototype);
}
if (typeof WebGL2RenderingContext !== 'undefined') {
hookGetParameter(WebGL2RenderingContext.prototype);
}
var NOISE_PROBABILITY = 0.02;
function addPixelNoise(data) {
for (var i = 0; i < data.length; i++) {
if (Math.random() < NOISE_PROBABILITY) {
var value = data[i] + (Math.random() < 0.5 ? -1 : 1);
data[i] = value < 0 ? 0 : value > 255 ? 255 : value;
}
}
return data;
}
var canvasProto = typeof HTMLCanvasElement !== 'undefined' ? HTMLCanvasElement.prototype : null;
var ctx2dProto = typeof CanvasRenderingContext2D !== 'undefined' ? CanvasRenderingContext2D.prototype : null;
if (!canvasProto || !ctx2dProto || typeof ctx2dProto.getImageData !== 'function') {
return;
}
var rawGetImageData = ctx2dProto.getImageData;
ctx2dProto.getImageData = wrapFunction(rawGetImageData, function (_self, args, orig) {
var imageData = orig();
try {
addPixelNoise(imageData.data);
} catch (e) {
}
return imageData;
});
var ctx2d_getContext = HTMLCanvasElement.prototype.getContext;
HTMLCanvasElement.prototype.getContext = wrapFunction(
ctx2d_getContext,
function (canvas, args, orig) {
var result = orig();
if (result) {
try {
canvas.__crawlrs_ctx_type = args[0];
} catch (e) {
}
}
return result;
},
);
canvasProto.toDataURL = wrapFunction(canvasProto.toDataURL, function (canvas, args, orig) {
try {
if (canvas.__crawlrs_ctx_type !== '2d' || canvas.width === 0 || canvas.height === 0) {
return orig();
}
var ctx = canvas.getContext('2d');
if (!ctx) {
return orig();
}
var imageData = rawGetImageData.call(ctx, 0, 0, canvas.width, canvas.height);
addPixelNoise(imageData.data);
var copy = document.createElement('canvas');
copy.width = canvas.width;
copy.height = canvas.height;
copy.getContext('2d').putImageData(imageData, 0, 0);
return orig(copy);
} catch (e) {
return orig();
}
});
})();