Skip to content

Commit 04fc291

Browse files
fix(computer-use): scale scroll amounts in TypeScript
1 parent 70b4b0f commit 04fc291

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

templates/typescript/computer-use/tools/computer.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,19 @@ export class ComputerTool implements BaseAnthropicTool {
190190
await this.page.waitForTimeout(100);
191191
}
192192

193-
const amount = scrollAmountValue || 100;
193+
const pageDimensions = await this.page.evaluate(() => {
194+
return { h: window.innerHeight, w: window.innerWidth };
195+
});
196+
const pagePartitions = 25;
197+
const scrollFactor = (scrollAmountValue || 10) / pagePartitions;
194198

195199
if (scrollDirection === 'down' || scrollDirection === 'up') {
200+
const amount = pageDimensions.h * scrollFactor;
201+
console.log(`Scrolling ${amount / pageDimensions.h * 100}% ${scrollDirection}`);
196202
await this.page.mouse.wheel(0, scrollDirection === 'down' ? amount : -amount);
197203
} else {
204+
const amount = pageDimensions.w * scrollFactor;
205+
console.log(`Scrolling ${amount / pageDimensions.w * 100}% ${scrollDirection}`);
198206
await this.page.mouse.wheel(scrollDirection === 'right' ? amount : -amount, 0);
199207
}
200208

0 commit comments

Comments
 (0)