"""Starter Playwright script template for web-act workers (Phase 3D)."""

from __future__ import annotations

EXPLORE_PY_TEMPLATE = '''\
"""Web-act starter — write relative to scope root (e.g. explore.py)."""
import json
import os

from utils.web_act_helpers import safe_goto


def main() -> None:
    launch_kwargs = {}
    raw = os.environ.get("MUGI_PLAYWRIGHT_LAUNCH_KWARGS", "{}")
    try:
        import json as _json

        launch_kwargs = _json.loads(raw) if raw.strip() else {}
    except Exception:
        launch_kwargs = {}

    from playwright.sync_api import sync_playwright

    with sync_playwright() as p:
        browser = p.chromium.launch(**launch_kwargs)
        page = browser.new_page()
        safe_goto(page, "https://example.com")
        page.wait_for_load_state("domcontentloaded")
        title = (page.title() or "").strip()
        os.makedirs("screenshots", exist_ok=True)
        page.screenshot(path="screenshots/result.png", full_page=True)
        browser.close()

    with open("result.json", "w", encoding="utf-8") as f:
        json.dump({"ok": True, "answer": title or "page loaded"}, f)


if __name__ == "__main__":
    main()
'''
