eoka 0.17.1

Stealth browser automation for Rust. Puppeteer/Playwright alternative with anti-bot bypass.
Documentation
// Canvas noise (gated by `StealthConfig::fingerprint_spoofing`). Readback and export
// use the native getter and apply the same noise once. HTML and offscreen canvases
// get the same noise, in pages and in workers, so a worker's canvas agrees with the
// page's.
const _eoka_noisePixels = (img) => {
    const data = img.data;
    let s = (__EOKA_NOISE_SEED__ >>> 0) || 1;
    for (let i = 0; i < data.length; i += 4) {
        s = _eoka_lcg(s);
        // Partially transparent RGB is quantized by the canvas backing store.
        // Leave it alone so exporting cannot change the readback noise.
        if (data[i + 3] === 255) data[i] = data[i] ^ (s & 1);
    }
    return img;
};
// A noised copy of `canvas` made with `blank`, or `canvas` itself when it
// cannot be read, so native export failures (tainted, detached) still throw.
const _eoka_noisedCopy = (canvas, blank, nativeGetImageData) => {
    const w = canvas.width | 0, h = canvas.height | 0;
    if (w <= 0 || h <= 0) return canvas;
    try {
        const tmp = blank(w, h);
        const tctx = tmp.getContext('2d');
        tctx.drawImage(canvas, 0, 0);
        const img = nativeGetImageData.call(tctx, 0, 0, w, h);
        tctx.putImageData(_eoka_noisePixels(img), 0, 0);
        return tmp;
    } catch(e) {
        return canvas;
    }
};
const _eoka_canvasKinds = [
    ['HTMLCanvasElement', 'CanvasRenderingContext2D', ['toDataURL', 'toBlob'], (w, h) => {
        const c = document.createElement('canvas');
        c.width = w; c.height = h;
        return c;
    }],
    ['OffscreenCanvas', 'OffscreenCanvasRenderingContext2D', ['convertToBlob'], (w, h) => new OffscreenCanvas(w, h)],
];
for (const [canvasName, contextName, exports, blank] of _eoka_canvasKinds) {
    const Canvas = globalThis[canvasName], Context = globalThis[contextName];
    if (typeof Canvas !== 'function' || typeof Context !== 'function') continue;
    const nativeGetImageData = Context.prototype.getImageData;
    for (const name of exports) {
        _eoka_patchMethod(Canvas.prototype, name, (original) => function(...args) {
            // A non-canvas receiver has no size, passes through and throws natively.
            return original.apply(_eoka_noisedCopy(this, blank, nativeGetImageData), args);
        });
    }
    _eoka_patchMethod(Context.prototype, 'getImageData', (original) => function(...args) {
        return _eoka_noisePixels(original.apply(this, args));
    });
}