import re
from playwright.sync_api import sync_playwright

URL = "https://slot-machine.zybg4298.odns.fr/#/291qo"
SPIN = re.compile(r"(jouer|lancer|tourner|spin|play|go)", re.I)


def main():
    with sync_playwright() as p:
        browser = p.chromium.launch()
        ctx = browser.new_context(ignore_https_errors=True)
        page = ctx.new_page()

        # on intercepte les appels xhr/fetch et leur reponse
        def on_response(resp):
            req = resp.request
            if req.resource_type in ("xhr", "fetch"):
                try:
                    body = resp.text()[:300]
                except Exception:
                    body = "(illisible)"
                print("Appel:", req.method, req.url)
                print("Corps envoye:", req.post_data)
                print("Statut:", resp.status)
                print("Reponse:", body)
                print("---")

        page.on("response", on_response)
        page.goto(URL, wait_until="networkidle", timeout=30000)
        page.mouse.click(640, 360)
        page.wait_for_timeout(6000)
        print("LocalStorage:", page.evaluate("JSON.stringify(localStorage)"))
        print("SessionStorage:", page.evaluate("JSON.stringify(sessionStorage)"))
        print("Cookies:", ctx.cookies())
        ctx.close()
        browser.close()


if __name__ == "__main__":
    main()
