@@ -48,6 +48,7 @@ class EnvArgs(DataClassJsonMixin):
4848 slow_mo : Optional [int ] = None # use default value from BrowserGym
4949 storage_state : Optional [str | Path | dict ] = None
5050 task_kwargs : Optional [dict ] = None # use default value from BrowserGym
51+ pre_observation_delay : float = 0.5 # seconds, wait for JS events to be fired
5152
5253 def make_env (
5354 self , action_mapping , exp_dir , exp_task_kwargs : dict = {}, use_raw_page_output = True
@@ -71,6 +72,8 @@ def make_env(
7172 extra_kwargs ["viewport" ] = self .viewport
7273 if self .slow_mo is not None :
7374 extra_kwargs ["slow_mo" ] = self .slow_mo
75+ if self .pre_observation_delay is not None :
76+ extra_kwargs ["pre_observation_delay" ] = self .pre_observation_delay
7477 if self .storage_state :
7578 extra_kwargs ["pw_context_kwargs" ] = {"storage_state" : self .storage_state }
7679 if self .task_kwargs is not None :
@@ -142,6 +145,12 @@ class StepTimestamps:
142145 env_stop : float = 0
143146 agent_start : float = 0
144147 agent_stop : float = 0
148+ wait_for_page_loading_start : float = 0
149+ wait_for_page_loading_stop : float = 0
150+ validation_start : float = 0
151+ validation_stop : float = 0
152+ get_observation_start : float = 0
153+ get_observation_stop : float = 0
145154
146155
147156@dataclass
@@ -199,6 +208,12 @@ def from_step(self, env: gym.Env, action: str, obs_preprocessor: callable):
199208 t .action_exec_start = env_info ["action_exec_start" ] # start
200209 t .action_exect_after_timeout = env_info ["action_exec_stop" ]
201210 t .action_exec_stop = env_info ["action_exec_stop" ] - env_info ["action_exec_timeout" ]
211+ t .wait_for_page_loading_start = env_info .get ("wait_for_page_loading_start" , None )
212+ t .wait_for_page_loading_stop = env_info .get ("wait_for_page_loading_stop" , None )
213+ t .validation_start = env_info .get ("validation_start" , None )
214+ t .validation_stop = env_info .get ("validation_stop" , None )
215+ t .get_observation_start = env_info .get ("get_observation_start" , None )
216+ t .get_observation_stop = env_info .get ("get_observation_stop" , None )
202217
203218 if obs_preprocessor :
204219 self .obs = obs_preprocessor (self .obs )
@@ -447,6 +462,10 @@ def run(self):
447462 logger .debug ("Sending action to environment." )
448463 step_info .from_step (env , action , obs_preprocessor = agent .obs_preprocessor )
449464 logger .debug ("Environment stepped." )
465+ if step_info .is_done :
466+ logger .debug (
467+ f"Episode done: terminated: { step_info .terminated } , truncated: { step_info .truncated } ."
468+ )
450469
451470 except Exception as e :
452471 err_msg = f"Exception uncaught by agent or environment in task { self .env_args .task_name } .\n { type (e ).__name__ } :\n { e } "
0 commit comments