Skip to content

Commit 2b13dec

Browse files
fix(computer-use): python template scrolling scale
1 parent 04fc291 commit 2b13dec

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

templates/python/computer-use/tools/computer.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,16 +316,26 @@ async def __call__(
316316
await self.page.mouse.move(x, y)
317317

318318
# Map scroll directions to Playwright's wheel events
319+
page_dimensions = await self.page.evaluate(
320+
"() => Promise.resolve({ h: window.innerHeight, w: window.innerWidth })"
321+
)
322+
page_partitions = 25
323+
scroll_factor = scroll_amount / page_partitions
324+
page_width = page_dimensions['w']
325+
page_height = page_dimensions['h']
326+
319327
delta_x = 0
320328
delta_y = 0
321329
if scroll_direction == "up":
322-
delta_y = -scroll_amount * 100
330+
delta_y = -scroll_factor * page_height
323331
elif scroll_direction == "down":
324-
delta_y = scroll_amount * 100
332+
delta_y = scroll_factor * page_height
325333
elif scroll_direction == "left":
326-
delta_x = -scroll_amount * 100
334+
delta_x = -scroll_factor * page_width
327335
elif scroll_direction == "right":
328-
delta_x = scroll_amount * 100
336+
delta_x = scroll_factor * page_width
337+
338+
print(f"Scrolling {abs(delta_x) if delta_x != 0 else abs(delta_y):.02f} pixels {scroll_direction}")
329339

330340
await self.page.mouse.wheel(delta_x=delta_x, delta_y=delta_y)
331341
return await self.screenshot()
@@ -385,4 +395,4 @@ async def __call__(
385395

386396
return await super().__call__(
387397
action=action, text=text, coordinate=coordinate, key=key, **kwargs
388-
)
398+
)

0 commit comments

Comments
 (0)