| 234 | self.context_manager.__exit__() |
| 235 | |
| 236 | def step( |
| 237 | self, action: Action |
| 238 | ) -> tuple[dict[str, Observation], float, bool, bool, dict[str, Any]]: |
| 239 | if not self.reset_finished: |
| 240 | raise RuntimeError("Call reset first before calling step.") |
| 241 | |
| 242 | success = False |
| 243 | fail_error = "" |
| 244 | try: |
| 245 | self.page = execute_action( |
| 246 | action, |
| 247 | self.page, |
| 248 | self.context, |
| 249 | self.observation_handler.action_processor, |
| 250 | ) |
| 251 | success = True |
| 252 | except Exception as e: |
| 253 | fail_error = str(e) |
| 254 | |
| 255 | # hard sleep TODO[shuyanzh] suboptimal, may need to check network |
| 256 | if self.sleep_after_execution > 0: |
| 257 | time.sleep(self.sleep_after_execution) |
| 258 | |
| 259 | images = self.modify_page() |
| 260 | |
| 261 | observation = self._get_obs() |
| 262 | observation_metadata = self._get_obs_metadata() |
| 263 | |
| 264 | info = { |
| 265 | "page": DetachedPage(self.page.url, self.page.content()), |
| 266 | "fail_error": fail_error, |
| 267 | "observation_metadata": observation_metadata, |
| 268 | "images": images, |
| 269 | } |
| 270 | |
| 271 | msg = ( |
| 272 | observation, |
| 273 | float(success), # reward |
| 274 | False, # terminated |
| 275 | False, # truncated |
| 276 | info, |
| 277 | ) |
| 278 | return msg |
| 279 | |
| 280 | def modify_page(self): |
| 281 | self.page.wait_for_timeout(500) |