scroll
Scroll web pages in specified directions (up, down, left, right) with customizable pixel counts and scrolling behavior to enhance browser automation tasks.
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)Handler function for the 'scroll' tool that parses input parameters using ScrollSchema, computes scroll distance, and executes scrolling in the specified direction using Playwright's page.evaluate method on the current page.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 defining the input parameters for the scroll tool: direction (up/down/left/right), optional pixels, and behavior (auto/smooth).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)Registration of the 'scroll' tool in the ListTools response, including name, description, and inputSchema matching the 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' } } } },