scroll
Automate page scrolling in specified directions (up, down, left, right) with customizable pixel counts and smooth or auto behaviors using the MCP Browser Server.
Instructions
Scroll the page in the specified direction
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| behavior | No | Scrolling behavior | auto |
| direction | No | Direction to scroll | down |
| pixels | No | Number of pixels to scroll (optional) |
Implementation Reference
- src/index.ts:761-807 (handler)The main handler for the 'scroll' tool. Parses input using ScrollSchema, calculates scroll distance (default 100px), executes scrolling via page.evaluate using window.scrollTo based on direction.case 'scroll': { if (!currentPage) { throw new Error('No browser page available. Launch a browser first.'); } const params = ScrollSchema.parse(args); const { direction, pixels, behavior } = params; // Determine scroll distance const scrollDistance = pixels !== undefined ? pixels : 100; // Scroll the page await currentPage.evaluate(({ direction, scrollDistance, behavior }) => { let newX = window.scrollX; let newY = window.scrollY; switch (direction) { case 'down': newY += scrollDistance; break; case 'up': newY -= scrollDistance; break; case 'right': newX += scrollDistance; break; case 'left': newX -= scrollDistance; break; } window.scrollTo({ top: newY, left: newX, behavior: behavior }); }, { direction, scrollDistance, behavior }); return { content: [ { type: 'text', text: `Scrolled ${direction} by ${scrollDistance} pixels` } ] }; }
- src/index.ts:72-76 (schema)Zod schema for validating 'scroll' tool inputs: direction (up/down/left/right, default 'down'), optional pixels, behavior (auto/smooth, default 'auto').const ScrollSchema = z.object({ direction: z.enum(['up', 'down', 'left', 'right']).default('down'), pixels: z.number().optional(), behavior: z.enum(['auto', 'smooth']).default('auto') });
- src/index.ts:363-386 (registration)Tool registration in the ListTools response, defining name 'scroll', description, and inputSchema matching ScrollSchema.name: 'scroll', description: 'Scroll the page in the specified direction', inputSchema: { type: 'object', properties: { direction: { type: 'string', enum: ['up', 'down', 'left', 'right'], default: 'down', description: 'Direction to scroll' }, pixels: { type: 'number', description: 'Number of pixels to scroll (optional)' }, behavior: { type: 'string', enum: ['auto', 'smooth'], default: 'auto', description: 'Scrolling behavior' } } } },