puppeteer-extra
puppeteer-extra copied to clipboard
[Feature] playwright-python by stealth.min.js
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')
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)