scroll
Scroll the page vertically by a pixel amount. Choose direction up or down for browser automation.
Instructions
Scrolls the page vertically by a pixel amount. Browser-only — for mobile scrolling use swipe. Only supports up/down; no horizontal scrolling.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| direction | Yes | Scroll direction | |
| pixels | No | Number of pixels to scroll |
Implementation Reference
- src/tools/scroll.tool.ts:17-41 (handler)The core execution logic for the scroll tool: validates session type is 'browser', computes scroll amount (positive for down, negative for up), and executes window.scrollBy(0, amount) via browser.execute(). Returns success or error text.
export const scrollAction = async (direction: 'up' | 'down', pixels = 500): Promise<CallToolResult> => { try { const browser = getBrowser(); const state = getState(); const metadata = state.sessionMetadata.get(state.currentSession); const sessionType = metadata?.type; if (sessionType !== 'browser') { throw new Error('scroll only works in browser sessions. For mobile, use the swipe tool.'); } const scrollAmount = direction === 'down' ? pixels : -pixels; await browser.execute((amount) => { window.scrollBy(0, amount); }, scrollAmount); return { content: [{ type: 'text', text: `Scrolled ${direction} ${pixels} pixels` }], }; } catch (e) { return { isError: true, content: [{ type: 'text', text: `Error scrolling: ${e}` }], }; } - src/tools/scroll.tool.ts:44-45 (handler)The scrollTool callback adapter: destructures direction/pixels and delegates to scrollAction.
export const scrollTool: ToolCallback = async ({ direction, pixels = 500 }: { direction: 'up' | 'down'; pixels?: number }) => scrollAction(direction, pixels); - src/tools/scroll.tool.ts:7-15 (schema)scrollToolDefinition: defines tool name ('scroll'), description, annotations, and input schema (direction enum up/down, optional pixels with default 500).
export const scrollToolDefinition: ToolDefinition = { name: 'scroll', description: 'Scrolls the page vertically by a pixel amount. Browser-only — for mobile scrolling use swipe. Only supports up/down; no horizontal scrolling.', annotations: { title: 'Scroll Page', destructiveHint: false }, inputSchema: { direction: z.enum(['up', 'down']).describe('Scroll direction'), pixels: z.number().optional().default(500).describe('Number of pixels to scroll'), }, }; - src/server.ts:132-132 (registration)Registration of the scroll tool in the MCP server, wrapping scrollTool with withRecording('scroll', scrollTool).
registerTool(scrollToolDefinition, withRecording('scroll', scrollTool)); - Code generator for the scroll recording step: generates 'await browser.execute(() => window.scrollBy(0, scrollAmount));' based on direction and pixels.
case 'scroll': { const scrollAmount = (p.direction as string) === 'down' ? (p.pixels as number) : -(p.pixels as number); return `await browser.execute(() => window.scrollBy(0, ${scrollAmount}));`; }