fix: wait for Steam navigation readiness

This commit is contained in:
Kurt Himebauch committed 2026-10-28 18:37:19 -04:00
1 parent ea8feebea7
commit ab7390e844
4 files changed
+81 -6

No files matched your search

@@ -1032,6 +1032,28 @@ def request_timeout(req, default):
return timeout
def wait_for_steam_ui(agent_dir, timeout=120):
"""Wait for Steam's initialized shared app store before sending a navigation URL."""
timeout = request_timeout({"timeout": timeout}, 120)
deadline = time.monotonic() + timeout
expression = "Boolean(globalThis.appStore?.m_bIsInitialized)"
while True:
remaining = deadline - time.monotonic()
if remaining <= 0:
raise AgentError("STEAM_UI_TIMEOUT", "Steam's UI router did not become ready")
try:
result = cdp_eval(agent_dir, expression, await_promise=False,
timeout=min(5, max(0.25, remaining)))
if result.get("value") is True:
return
except OSError:
pass
except AgentError as error:
if error.code not in ("NO_DEVTOOLS", "DEVTOOLS_UNREACHABLE", "NO_TARGET", "TIMEOUT"):
raise
time.sleep(min(0.25, max(0, deadline - time.monotonic())))
def handle(agent_dir, req):
kind = req.get("kind")
if kind == "ping":
@@ -1055,6 +1077,7 @@ def handle(agent_dir, req):
if not isinstance(url, str) or not re.fullmatch(
r"steam://(?:open/downloads|uninstall/[1-9][0-9]{0,9})", url):
raise AgentError("INVALID_REQUEST", "Steam navigation URL is not supported")
wait_for_steam_ui(agent_dir, req.get("timeout", 120))
try:
subprocess.Popen(["steam", url], stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL, start_new_session=True)