| 977 | return [r if r is not None else {"ok": False, "error": "missing"} for r in results] |
| 978 | |
| 979 | async def _dispatch_call(self, call: dict[str, Any]) -> Any: |
| 980 | action = str(call.get("action") or "").strip().lower().replace("-", "_") |
| 981 | bid = call.get("browser_id") |
| 982 | if action == "open": |
| 983 | return await self.open(call.get("url") or "") |
| 984 | if action == "screenshot": |
| 985 | return await self.screenshot_file( |
| 986 | bid, |
| 987 | quality=int(call.get("quality") or 80), |
| 988 | full_page=bool(call.get("full_page")), |
| 989 | path=call.get("path") or "", |
| 990 | ) |
| 991 | if action == "list": |
| 992 | return await self.list(include_content=bool(call.get("include_content"))) |
| 993 | if action == "state": |
| 994 | return await self.state(bid) |
| 995 | if action in {"set_active", "setactive", "activate", "focus"}: |
| 996 | return await self.set_active(bid) |
| 997 | if action == "navigate": |
| 998 | return await self.navigate(bid, call.get("url") or "") |
| 999 | if action == "back": |
| 1000 | return await self.back(bid) |
| 1001 | if action == "forward": |
| 1002 | return await self.forward(bid) |
| 1003 | if action == "reload": |
| 1004 | return await self.reload(bid) |
| 1005 | if action == "content": |
| 1006 | payload = None |
| 1007 | sels = call.get("selectors") |
| 1008 | sel = call.get("selector") |
| 1009 | if sels: |
| 1010 | payload = {"selectors": sels} |
| 1011 | elif sel: |
| 1012 | payload = {"selector": sel} |
| 1013 | return await self.content(bid, payload) |
| 1014 | if action == "detail": |
| 1015 | ref = call.get("ref") |
| 1016 | if ref is None: |
| 1017 | raise ValueError("detail requires ref") |
| 1018 | return await self.detail(bid, ref) |
| 1019 | if action == "click": |
| 1020 | ref = call.get("ref") |
| 1021 | if ref is None and (call.get("x") or call.get("y")): |
| 1022 | return await self.mouse( |
| 1023 | bid, |
| 1024 | "click", |
| 1025 | float(call.get("x") or 0), |
| 1026 | float(call.get("y") or 0), |
| 1027 | button=call.get("button") or "left", |
| 1028 | modifiers=self._normalize_modifiers(call.get("modifiers")), |
| 1029 | ) |
| 1030 | if ref is None: |
| 1031 | raise ValueError("click requires ref") |
| 1032 | return await self.click( |
| 1033 | bid, ref, |
| 1034 | modifiers=self._normalize_modifiers(call.get("modifiers")), |
| 1035 | focus_popup=call.get("focus_popup"), |
| 1036 | ) |