@@ -28,8 +28,8 @@ def model_post_init(self, __context: Any):
2828 "browser_mouse_click_xy" : self .browser_mouse_click_xy ,
2929 }
3030
31- def initialize (self ):
32- self ._loop = asyncio .get_event_loop ()
31+ def initialize (self , loop : asyncio . AbstractEventLoop | None = None ):
32+ self ._loop = loop or asyncio .get_event_loop ()
3333 self ._loop .run_until_complete (self .ainitialize ())
3434
3535 async def ainitialize (self ):
@@ -53,7 +53,7 @@ async def browser_click(self, selector: str):
5353 """
5454 Click on a selector.
5555 """
56- await self ._page .click (selector )
56+ await self ._page .click (selector , timeout = 3000 , strict = True )
5757
5858 async def browser_drag (self , from_selector : str , to_selector : str ):
5959 """
@@ -71,7 +71,7 @@ async def browser_hover(self, selector: str):
7171 """
7272 Hover over a given element.
7373 """
74- await self ._page .hover (selector )
74+ await self ._page .hover (selector , timeout = 3000 , strict = True )
7575
7676 async def browser_select_option (self , selector : str , value : str ):
7777 """
@@ -105,7 +105,11 @@ def page_axtree(self):
105105
106106 def step (self , action : ToolCallAction ):
107107 fn = self ._actions [action .function .name ]
108- action_result = self ._loop .run_until_complete (fn (** action .function .arguments ))
108+ try :
109+ action_result = self ._loop .run_until_complete (fn (** action .function .arguments ))
110+ except Exception as e :
111+ logger .error (f"Error executing action { action .function .name } : { e } " )
112+ action_result = f"Error executing action { action .function .name } : { e } "
109113 html = self .page_html ()
110114 screenshot = self .page_screenshot ()
111115 axtree = self .page_axtree ()
0 commit comments