Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/tools/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,42 @@ const screenshot: Tool = {
},
};


const scrollToEndSchema = z.object({
delay: z.number().optional().describe('Delay in milliseconds between scroll steps (default: 100)'),
step: z.number().optional().describe('Pixels to scroll in each step (default: 100)'),
});

const scrollToEnd: Tool = {
capability: 'core',
schema: {
name: 'browser_scroll_to_end',
description: 'Scroll down the page gradually to the bottom',
inputSchema: zodToJsonSchema(scrollToEndSchema),
},

handle: async (context, params) => {
const validatedParams = scrollToEndSchema.parse(params);
return await context.currentTab().runAndWaitWithSnapshot(async tab => {
await tab.page.evaluate(async ({ delay, step }) => {
const scrollDelay = ms => new Promise(resolve => setTimeout(resolve, ms));
const scrollStep = step || 100;
const scrollDelay_ms = delay || 100;

for (let i = 0; i < document.body.scrollHeight; i += scrollStep) {
window.scrollTo(0, i);
await scrollDelay(scrollDelay_ms);
}
}, {
delay: validatedParams.delay || 100,
step: validatedParams.step || 100
});
}, {
status: 'Scrolled page to bottom',
});
},
};

export default [
snapshot,
click,
Expand All @@ -187,4 +223,5 @@ export default [
type,
selectOption,
screenshot,
scrollToEnd,
];