@@ -192,17 +192,25 @@ def to_params(self) -> BetaToolComputerUse20241022Param:
192
192
"""Params describing the tool. Used by Claude to understand this is a computer use tool."""
193
193
return {"name" : self .name , "type" : self .api_type , ** self .options }
194
194
195
- def __init__ (self , page : Page , use_cursor : bool = True ):
195
+ def __init__ (
196
+ self ,
197
+ page : Page ,
198
+ use_cursor : bool = True ,
199
+ screenshot_wait_until : Literal ["load" , "domcontentloaded" , "networkidle" ]
200
+ | None = None ,
201
+ ):
196
202
"""Initializes the PlaywrightComputerTool.
197
203
198
204
Args:
199
205
page: The Async Playwright page to interact with.
200
206
use_cursor: Whether to display the cursor in the screenshots or not.
207
+ screenshot_wait_until: Optional, wait until the page is in a specific state before taking a screenshot. Default does not wait
201
208
"""
202
209
super ().__init__ ()
203
210
self .page = page
204
211
self .use_cursor = use_cursor
205
212
self .mouse_position : tuple [int , int ] = (0 , 0 )
213
+ self .screenshot_wait_until = screenshot_wait_until
206
214
207
215
async def __call__ (
208
216
self ,
@@ -284,6 +292,9 @@ async def __call__(
284
292
285
293
async def screenshot (self ) -> ToolResult :
286
294
"""Take a screenshot of the current screen and return the base64 encoded image."""
295
+ if self .screenshot_wait_until is not None :
296
+ await self .page .wait_for_timeout (self .screenshot_wait_until )
297
+ await self .page .wait_for_load_state ()
287
298
screenshot = await self .page .screenshot ()
288
299
image = Image .open (io .BytesIO (screenshot ))
289
300
img_small = image .resize ((self .width , self .height ), Image .LANCZOS )
0 commit comments