how to get Twitter cookie and login with headless chromium
0xfocu5 opened this issue · comments
I used this code to get Twitter cookie
npx playwright codegen twitter.com --save-storage=auth.json
but the cookie can only use in
browser = playwright.chromium.launch(headless=False, proxy={"server": "http://127.0.0.1:7890"})
context = browser.new_context(storage_state="auth.json")
when I run
browser = playwright.chromium.launch(headless=True, proxy={"server": "http://127.0.0.1:7890"})
context = browser.new_context(storage_state="auth.json")
It failed.
Maybe Twitter filters by the User-Agent? You can hard-code the user-Agent when creating a new context.
context = browser.new_context(storage_state="auth.json", user_agent="....")
Since this is not a Playwright bug and more the website behaves different / has some bot protection in place, I'm going to close it for now.