muse-chat-api.py: cdp_call skips CDP event chatter
This commit is contained in:
@@ -265,14 +265,20 @@ def cmd_sidechat_create(ws):
|
||||
|
||||
def cdp_call(ws, method, params=None):
|
||||
"""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
|
||||
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 {}}))
|
||||
for _ in range(20):
|
||||
resp = json.loads(ws.recv())
|
||||
if resp.get("id") != cid:
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user