muse-chat-api.py: cdp_call skips CDP event chatter

This commit is contained in:
operator-main
2026-10-04 01:25:44 +00:00
parent 566edf20c6
commit 1c386ca6bb
+12 -6
View File
@@ -265,14 +265,20 @@ def cmd_sidechat_create(ws):
def cdp_call(ws, method, params=None): def cdp_call(ws, method, params=None):
"""Raw CDP method call for non-Runtime domains (DOM, Page, ...). """Raw CDP method call for non-Runtime domains (DOM, Page, ...).
The ev() helper only speaks Runtime.evaluate; uploads need DOM.""" The ev() helper only speaks Runtime.evaluate; uploads need DOM.
Skips CDP event chatter (messages without our id) while waiting."""
cdp_call.counter += 1 cdp_call.counter += 1
ws.send(json.dumps({"id": cdp_call.counter, "method": method, cid = cdp_call.counter
ws.send(json.dumps({"id": cid, "method": method,
"params": params or {}})) "params": params or {}}))
resp = json.loads(ws.recv()) for _ in range(20):
if "error" in resp: resp = json.loads(ws.recv())
raise RuntimeError("CDP %s failed: %s" % (method, resp["error"])) if resp.get("id") != cid:
return resp.get("result", {}) continue # event, not our response
if "error" in resp:
raise RuntimeError("CDP %s failed: %s" % (method, resp["error"]))
return resp.get("result", {})
raise RuntimeError("CDP %s: no response after 20 reads" % method)
cdp_call.counter = 100 cdp_call.counter = 100