From 04fc291aa242eed5b0fb840f0382321d53b907f3 Mon Sep 17 00:00:00 2001 From: Matt Marangoni Date: Wed, 11 Jun 2025 12:21:29 -0400 Subject: [PATCH 1/3] fix(computer-use): scale scroll amounts in TypeScript --- templates/typescript/computer-use/tools/computer.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/templates/typescript/computer-use/tools/computer.ts b/templates/typescript/computer-use/tools/computer.ts index 126775f..d299fce 100644 --- a/templates/typescript/computer-use/tools/computer.ts +++ b/templates/typescript/computer-use/tools/computer.ts @@ -190,11 +190,19 @@ export class ComputerTool implements BaseAnthropicTool { await this.page.waitForTimeout(100); } - const amount = scrollAmountValue || 100; + const pageDimensions = await this.page.evaluate(() => { + return { h: window.innerHeight, w: window.innerWidth }; + }); + const pagePartitions = 25; + const scrollFactor = (scrollAmountValue || 10) / pagePartitions; if (scrollDirection === 'down' || scrollDirection === 'up') { + const amount = pageDimensions.h * scrollFactor; + console.log(`Scrolling ${amount / pageDimensions.h * 100}% ${scrollDirection}`); await this.page.mouse.wheel(0, scrollDirection === 'down' ? amount : -amount); } else { + const amount = pageDimensions.w * scrollFactor; + console.log(`Scrolling ${amount / pageDimensions.w * 100}% ${scrollDirection}`); await this.page.mouse.wheel(scrollDirection === 'right' ? amount : -amount, 0); } From 2b13decaeb82ff7a0b295701e32a2883653f6dff Mon Sep 17 00:00:00 2001 From: Matt Marangoni Date: Sat, 14 Jun 2025 18:41:08 -0400 Subject: [PATCH 2/3] fix(computer-use): python template scrolling scale --- .../python/computer-use/tools/computer.py | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/templates/python/computer-use/tools/computer.py b/templates/python/computer-use/tools/computer.py index 1a7f39e..00e3111 100644 --- a/templates/python/computer-use/tools/computer.py +++ b/templates/python/computer-use/tools/computer.py @@ -316,16 +316,26 @@ async def __call__( await self.page.mouse.move(x, y) # Map scroll directions to Playwright's wheel events + page_dimensions = await self.page.evaluate( + "() => Promise.resolve({ h: window.innerHeight, w: window.innerWidth })" + ) + page_partitions = 25 + scroll_factor = scroll_amount / page_partitions + page_width = page_dimensions['w'] + page_height = page_dimensions['h'] + delta_x = 0 delta_y = 0 if scroll_direction == "up": - delta_y = -scroll_amount * 100 + delta_y = -scroll_factor * page_height elif scroll_direction == "down": - delta_y = scroll_amount * 100 + delta_y = scroll_factor * page_height elif scroll_direction == "left": - delta_x = -scroll_amount * 100 + delta_x = -scroll_factor * page_width elif scroll_direction == "right": - delta_x = scroll_amount * 100 + delta_x = scroll_factor * page_width + + print(f"Scrolling {abs(delta_x) if delta_x != 0 else abs(delta_y):.02f} pixels {scroll_direction}") await self.page.mouse.wheel(delta_x=delta_x, delta_y=delta_y) return await self.screenshot() @@ -385,4 +395,4 @@ async def __call__( return await super().__call__( action=action, text=text, coordinate=coordinate, key=key, **kwargs - ) \ No newline at end of file + ) From 2bb650fddec53dad9a8c0834ff2235a76d6faeec Mon Sep 17 00:00:00 2001 From: Matt Marangoni Date: Sat, 14 Jun 2025 19:08:03 -0400 Subject: [PATCH 3/3] fix(computer-use): print scroll distance in pixels in TypeScript --- templates/typescript/computer-use/tools/computer.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/typescript/computer-use/tools/computer.ts b/templates/typescript/computer-use/tools/computer.ts index d299fce..df8e021 100644 --- a/templates/typescript/computer-use/tools/computer.ts +++ b/templates/typescript/computer-use/tools/computer.ts @@ -198,11 +198,11 @@ export class ComputerTool implements BaseAnthropicTool { if (scrollDirection === 'down' || scrollDirection === 'up') { const amount = pageDimensions.h * scrollFactor; - console.log(`Scrolling ${amount / pageDimensions.h * 100}% ${scrollDirection}`); + console.log(`Scrolling ${amount.toFixed(2)} pixels ${scrollDirection}`); await this.page.mouse.wheel(0, scrollDirection === 'down' ? amount : -amount); } else { const amount = pageDimensions.w * scrollFactor; - console.log(`Scrolling ${amount / pageDimensions.w * 100}% ${scrollDirection}`); + console.log(`Scrolling ${amount.toFixed(2)} pixels ${scrollDirection}`); await this.page.mouse.wheel(scrollDirection === 'right' ? amount : -amount, 0); }