scroll
Scroll a web page in any direction—up, down, left, or right—with optional pixel distance and smooth or automatic animation behavior.
Instructions
Scroll the page in the specified direction
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| direction | No | Direction to scroll | down |
| pixels | No | Number of pixels to scroll (optional) | |
| behavior | No | Scrolling behavior | auto |
Implementation Reference
- src/index.ts:72-76 (schema)Zod schema for the 'scroll' tool: defines direction (up/down/left/right, default 'down'), pixels (optional number), and 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:362-386 (registration)Tool registration for 'scroll' in the ListToolsRequestSchema handler. Provides name, description, and inputSchema with direction, pixels, and behavior fields.
{ 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' } } } }, - src/index.ts:761-807 (handler)Handler for the 'scroll' tool in the CallToolRequestSchema. Parses args via ScrollSchema, computes scroll distance (default 100px), uses page.evaluate to scroll via window.scrollTo, and returns a text result.
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` } ] }; }