add stealth

This commit is contained in:
Jan Bader
2026-04-05 22:22:49 +02:00
parent c53ded0ed5
commit d01776e2ab
3 changed files with 7 additions and 9 deletions

View File

@@ -4,6 +4,7 @@ import time
from pathlib import Path
from playwright.sync_api import sync_playwright, Page, Browser
from playwright_stealth import Stealth
from config import Config
@@ -194,21 +195,16 @@ def download_all_invoices() -> list[Path]:
output_dir.mkdir(parents=True, exist_ok=True)
saved = []
stealth = Stealth()
with sync_playwright() as p:
browser = p.chromium.launch(
headless=Config.BROWSER_HEADLESS,
args=["--disable-blink-features=AutomationControlled"],
)
context = browser.new_context(
user_agent=(
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
),
)
context = browser.new_context()
stealth.apply_stealth_sync(context)
page = context.new_page()
page.add_init_script(
"Object.defineProperty(navigator, 'webdriver', {get: () => undefined})"
)
page.set_default_timeout(Config.BROWSER_TIMEOUT)
login(page)

View File

@@ -19,6 +19,7 @@
packages = with pkgs; [
(python3.withPackages (ps: [
ps.playwright
ps.playwright-stealth
ps."python-dotenv"
]))
playwright-driver.browsers

View File

@@ -1,2 +1,3 @@
playwright>=1.40.0
playwright-stealth>=1.0.6
python-dotenv>=1.0.0