browser_scroll_by_pixels
Control browser scrolling precisely by specifying exact pixel amounts horizontally and vertically for automated web testing and interaction.
Instructions
Scroll by a specific number of pixels
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| x | Yes | Number of pixels to scroll horizontally | |
| y | Yes | Number of pixels to scroll vertically |
Implementation Reference
- src/tools/actionTools.ts:350-376 (registration)Registers the 'browser_scroll_by_pixels' MCP tool, including input schema (x, y pixels), description, and handler function that uses ActionService to perform the scroll.server.tool( 'browser_scroll_by_pixels', 'Scroll by a specific number of pixels', { x: z.number().describe('Number of pixels to scroll horizontally'), y: z.number().describe('Number of pixels to scroll vertically'), }, async ({ x, y }) => { try { const driver = stateManager.getDriver(); const actionService = new ActionService(driver); await actionService.scrollByPixels(x, y); return { content: [{ type: 'text', text: `Scrolled by pixels (${x}, ${y})` }], }; } catch (e) { return { content: [ { type: 'text', text: `Error scrolling by pixels: ${(e as Error).message}`, }, ], }; } } );
- src/tools/actionTools.ts:357-375 (handler)The MCP tool handler function that executes the scroll by instantiating ActionService and calling scrollByPixels.async ({ x, y }) => { try { const driver = stateManager.getDriver(); const actionService = new ActionService(driver); await actionService.scrollByPixels(x, y); return { content: [{ type: 'text', text: `Scrolled by pixels (${x}, ${y})` }], }; } catch (e) { return { content: [ { type: 'text', text: `Error scrolling by pixels: ${(e as Error).message}`, }, ], }; } }
- src/tools/actionTools.ts:353-356 (schema)Zod input schema defining parameters x (horizontal pixels) and y (vertical pixels) for the tool.{ x: z.number().describe('Number of pixels to scroll horizontally'), y: z.number().describe('Number of pixels to scroll vertically'), },
- src/services/actionService.ts:87-89 (helper)Supporting method in ActionService that executes the JavaScript window.scrollBy(x, y) via Selenium WebDriver to perform the actual scrolling.async scrollByPixels(x: number, y: number): Promise<void> { await this.driver.executeScript(`window.scrollBy(${x}, ${y});`); }