puppeteer-extra icon indicating copy to clipboard operation
puppeteer-extra copied to clipboard

[Feature] playwright-python by stealth.min.js

Open dly667 opened this issue 2 years ago • 1 comments

Can playwright-python use this library through page.evaluate(''stealth.min.js"), It didn't work when tested

async def main():
    async with async_playwright() as p:
        browser = await p.chromium.launch(headless=False)
        page = await browser.new_page()
        # await stealth_async(page)
        with open('data/stealth/js/test.js') as f:
            js = f.read()
        # page = await context.new_page()
        rs = await page.evaluate(js)
        # rs = await page.evaluate('()=>{%s}' %js)
        # print(rs)
        # await context.add_init_script('()=>{%s}' % js)

        await page.goto('https://bot.sannysoft.com')

dly667 avatar Jan 30 '23 10:01 dly667

It doesn't work, because some scripts require actual Playwright instance. For example: https://github.com/berstend/puppeteer-extra/blob/master/packages/puppeteer-extra-plugin-stealth/evasions/user-agent-override/index.js that require page:

  async onPageCreated(page) {
    // Determine the full user agent string, strip the "Headless" part
    let ua =
      this.opts.userAgent ||
      (await page.browser().userAgent()).replace('HeadlessChrome/', 'Chrome/')
      
    (...)
      
    const client =
      typeof page._client === 'function' ? page._client() : page._client
    client.send('Network.setUserAgentOverride', override)

RG9 avatar Jul 25 '23 15:07 RG9