eoka 0.14.3

Stealth browser automation for Rust. Puppeteer/Playwright alternative with anti-bot bypass.
Documentation

const _eoka_spoofed = new WeakMap();
const _eoka_origToString = Function.prototype.toString;
const _eoka_mark = (fn, name) => {
    if (typeof fn === 'function') {
        _eoka_spoofed.set(fn, name || fn.name || '');
    }
    return fn;
};
// A plain method, not a Proxy: a Proxy is exposed by the cyclic `__proto__`
// check (setting a function's prototype to an object inheriting from itself
// throws for a real function, but not through a Proxy). Method shorthand has
// no `prototype`, `name` "toString" and `length` 0, like the native.
const _eoka_toString = { toString() {
    if (typeof this === 'function' && _eoka_spoofed.has(this)) {
        const name = _eoka_spoofed.get(this);
        return name ? 'function ' + name + '() { [native code] }'
                    : 'function () { [native code] }';
    }
    return Reflect.apply(_eoka_origToString, this, arguments);
} }.toString;
Object.defineProperty(Function.prototype, 'toString', {
    ...Object.getOwnPropertyDescriptor(Function.prototype, 'toString'),
    value: _eoka_toString,
});
_eoka_mark(_eoka_toString, 'toString');

// Shared patch helpers. Every override replaces the property where the browser
// defines it (normally the interface prototype, never the instance), copies the
// native descriptor flags and keeps the native receiver checks by calling the
// original with `this`. Replacement methods use method-shorthand syntax, so
// like native members they have no `prototype` and cannot be constructed;
// their `name`/`length` match the original and `toString()` reports native
// code. `make(original)` returns the implementation.
const _eoka_patchMethod = (target, name, make) => {
    const desc = Object.getOwnPropertyDescriptor(target, name);
    if (!desc || typeof desc.value !== 'function') return false;
    const impl = make(desc.value);
    const fn = { [name](...args) { return impl.apply(this, args); } }[name];
    Object.defineProperty(fn, 'length', { value: desc.value.length, configurable: true });
    _eoka_mark(fn, name);
    Object.defineProperty(target, name, { ...desc, value: fn });
    return true;
};
const _eoka_patchGetter = (target, name, make) => {
    const desc = Object.getOwnPropertyDescriptor(target, name);
    const original = desc && desc.get;
    const impl = make(original);
    // Run the native getter first so a foreign receiver still throws natively.
    const get = Object.getOwnPropertyDescriptor({ get [name]() {
        if (original) original.call(this);
        return impl.call(this);
    } }, name).get;
    _eoka_mark(get, 'get ' + name);
    Object.defineProperty(target, name, {
        get,
        set: desc ? desc.set : undefined,
        enumerable: desc ? desc.enumerable : true,
        configurable: desc ? desc.configurable : true
    });
};

// An object of a native interface carrying read-only enumerable `fields`.
const _eoka_instance = (proto, fields) => {
    const object = Object.create(proto);
    for (const [key, value] of Object.entries(fields)) {
        Object.defineProperty(object, key, { value, enumerable: true });
    }
    return object;
};

// One step of the deterministic noise PRNG (LCG); streams are seeded from Rust.
const _eoka_lcg = (s) => (Math.imul(s >>> 0, 1664525) + 1013904223) >>> 0;