| 116 | asyncio.run(self.aclose()) |
| 117 | |
| 118 | async def astep( |
| 119 | self, action: Action |
| 120 | ) -> tuple[npt.NDArray[np.uint8], float, bool, bool, dict[str, object]]: |
| 121 | if not self.reset_finished: |
| 122 | raise RuntimeError("Call reset first before calling step.") |
| 123 | success = False |
| 124 | fail_error = "" |
| 125 | try: |
| 126 | self.page = await aexecute_action(action, self.page, self.context) |
| 127 | success = True |
| 128 | except Exception as e: |
| 129 | fail_error = str(e) |
| 130 | |
| 131 | try: |
| 132 | content = await self.page.content() |
| 133 | screenshot = png_bytes_to_numpy(await self.page.screenshot()) |
| 134 | except: |
| 135 | await self.page.wait_for_load_state("load") |
| 136 | content = await self.page.content() |
| 137 | screenshot = png_bytes_to_numpy(await self.page.screenshot()) |
| 138 | |
| 139 | return ( |
| 140 | screenshot, |
| 141 | float(success), |
| 142 | False, |
| 143 | False, |
| 144 | { |
| 145 | "page": DetachedPage(self.page.url, content), |
| 146 | "fail_error": fail_error, |
| 147 | }, |
| 148 | ) |
| 149 | |
| 150 | def step( |
| 151 | self, action: Action |