AtuboDad / playwright_stealth

playwright stealth
MIT License
541 stars 71 forks source link

Simply does not work #4

Open ThomasAitken opened 3 years ago

ThomasAitken commented 3 years ago

I ran both the synced and async versions of your basic user-agent example with Chromium (using the latest version of playwright-python, and the standard pip version of your package) and the screenshot in both cases shows a user agent containing "HeadlessChrome". Obviously, this is not as advertised - the user agent has not been edited.

AtuboDad commented 3 years ago

I ran both the synced and async versions of your basic user-agent example with Chromium (using the latest version of playwright-python, and the standard pip version of your package) and the screenshot in both cases shows a user agent containing "HeadlessChrome". Obviously, this is not as advertised - the user agent has not been edited.

which version of packages?

Version: playwright-python >= 1.9.0 playwright-stealth =1.0.5

Last: Use the Chrome on yourself OS.

Like this: `# -- coding: utf-8 -- from playwright.sync_api import sync_playwright from playwright_stealth import stealth_sync

playwright_sync = sync_playwright().start()

executablePath = 'C:\Google\Chrome\Application\chrome.exe' args = ['--no-sandbox', '--disable-infobars', '--lang=zh-CN', '--window-size=1920,1080', '--start-maximized'] ignoreDefaultArgs = ['--enable-automation'] browser = playwright_sync.chromium.launch(executable_path=executablePath, args=args, ignore_default_args=ignoreDefaultArgs, headless=True) page = browser.new_page() stealth_sync(page)

page.set_viewport_size({"width": 1920, "height": 969}) page.goto("https://bot.sannysoft.com/", timeout=180000) page.wait_for_timeout(3000) page.screenshot(path="example1.png") browser.close() playwright_sync.stop() `

ThomasAitken commented 3 years ago

Turns out that website (https://bot.sannysoft.com/) does show all tests passing using Chromium with my OS browser and with the playwright executable. But http://whatsmyuseragent.org/ fails with both.

kuranai commented 3 years ago

Hi, I also thought that it does not work, so I found this issue. But if I create a context and assign the user agent there, then it works for me. Here is the example of what works for me, in case anyone else ends up here:

from playwright.sync_api import sync_playwright
from playwright_stealth import stealth_sync

with sync_playwright() as p:
    browser = p.chromium.launch()
    context = browser.new_context(
        user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36",
    )
    page = context.new_page()
    stealth_sync(page)
    page.goto("https://bot.sannysoft.com/", wait_until="networkidle", timeout=10000)
    page.screenshot(path="screenshot.png")
    browser.close()

screenshot1 bot sannysoft com

JoshYuJump commented 4 months ago

Same Issue here.

stealth.min.js works for me

async with async_playwright() as p:
    # launch the browser
    browser = await p.chromium.launch()
    context = await browser.new_context(
        user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"
    )
    # stealth.min.js is a js script to prevent the website from detecting the crawler.
    await context.add_init_script(path="stealth.min.js")