ZFC-Digital / puppeteer-real-browser

This package is designed to bypass puppeteer's bot-detecting captchas such as Cloudflare. It acts like a real browser and can be managed with puppeteer.
https://www.npmjs.com/package/puppeteer-real-browser
MIT License
777 stars 95 forks source link

Cannot read properties of undefined (reading 'on') #197

Open KaiSeR1205 opened 1 month ago

KaiSeR1205 commented 1 month ago

Description

linux centos Chromium version 126.0.6478.114 start server run error : Cannot read properties of undefined (reading 'on')

Full steps to reproduce the issue

    error for here

    const { browser } = await connect({
        headless: false,
        turnstile: true,
        connectOption: { defaultViewport: null },
        disableXvfb: false,
    })

Issue Type

Support

Operating System

Linux

Do you use Docker?

None

KaiSeR1205 commented 1 month ago

async function pageController({ browser, page, proxy, turnstile, xvfbsession, pid, plugins, killProcess = false, chrome }) {

let solveStatus = turnstile
console.log(typeof page)
page.on('close', () => {
    solveStatus = false
});

browser.on('disconnected', async () => {
    solveStatus = false
    if (killProcess === true) {
        if (xvfbsession) try { xvfbsession.stopSync() } catch (err) { }
        if (chrome) try { chrome.kill() } catch (err) { console.log(err); }
        if (pid) try { kill(pid, 'SIGKILL', () => { }) } catch (err) { }
    }
});

async function turnstileSolver() {
    while (solveStatus) {
        await checkTurnstile({ page }).catch(() => { });
        await new Promise(r => setTimeout(r, 1000));
    }
    return
}

turnstileSolver()

if (proxy.username && proxy.password) await page.authenticate({ username: proxy.username, password: proxy.password });

if (plugins.length > 0) {
    for (const plugin of plugins) {
        plugin.onPageCreated(page)
    }
}

await page.evaluateOnNewDocument(() => {
    Object.defineProperty(MouseEvent.prototype, 'screenX', {
        get: function () {
            return this.clientX + window.screenX;
        }
    });

    Object.defineProperty(MouseEvent.prototype, 'screenY', {
        get: function () {
            return this.clientY + window.screenY;
        }
    });

});

const cursor = createCursor(page);
page.realCursor = cursor
page.realClick = cursor.click

return page

}

here console.log(typeof page) page.on('close', () => { solveStatus = false }); page undefined