#!/usr/bin/env python3
"""Playwright bypass for befar.com"""
import sys, time
from playwright.sync_api import sync_playwright

url = sys.argv[1] if len(sys.argv) > 1 else "https://www.befar.com/news/13.html"

with sync_playwright() as p:
    browser = p.chromium.launch(headless=True)
    context = browser.new_context(
        user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
        viewport={"width": 1920, "height": 1080}
    )
    page = context.new_page()
    try:
        page.goto(url, timeout=30000)
        time.sleep(3)
        content = page.content()
        outpath = "/tmp/befar_pw.html"
        with open(outpath, "w") as f:
            f.write(content)
        print("OK: %d bytes, title=%s" % (len(content), page.title()))
    except Exception as e:
        print("ERR: %s" % str(e))
    finally:
        browser.close()
