# SPDX-License-Identifier: Apache-2.0 """Hand one step to a person: a "Your turn" page with your message, their browser live and a Done button. Here the step is a verification code "sent to their phone" (the fixture's /verify page), which no agent can know. export WEBPILOT_URL=http://localhost:8931 WEBPILOT_TOKEN=cbu_... python examples/fixture_site.py & # the page that asks for the code python examples/python/handoff.py # waits up to 10 minutes python examples/python/handoff.py 120 # waits up to 2 minutes Open the printed link, type any 6 digits in the browser you see there, press Verify, then press Done. (Typing in the viewer needs take-over rights: the user's site policy `viewer_interactive`, or the host's CBU_VNC_INTERACTIVE=1.) A program acting for the person can also call wp.handoffs.resolve(id). """ from __future__ import annotations import os import sys from webpilot import WebPilot FIXTURE = os.environ.get("WEBPILOT_FIXTURE", "http://host.docker.internal:8765") wait_s = float(sys.argv[1]) if len(sys.argv) > 1 else 600.0 with WebPilot() as wp: tab = wp.open(f"{FIXTURE}/verify", mode="act") try: h = wp.handoffs.create( "Please enter the 6-digit code we sent to your phone, press Verify, then press Done.", reason="two_factor", tab_id=tab.id, expires_in_s=int(max(60, wait_s)), ) print(f"hand-off {h.id}: send this link to the person:\n {h.url}", flush=True) h = wp.handoffs.wait(h.id, timeout_s=wait_s) # long-polls; returns when Done is pressed or it expires print(f"hand-off {h.status}" + (f" ({h.note})" if h.note else "")) if h.status == "resolved": print("the page now says:", tab.read_text().strip().splitlines()[-1][:120]) else: print("nobody finished the step; report it and stop (do not try to get around it).") finally: tab.close()