scroll
codebolt.browser.scroll(direction: string, pixels: string): Promise<ScrollResponse>Scrolls the current page in a specified direction by a specified number of pixels.
Parameters
| Name | Type | Description |
|---|---|---|
| direction | string | The direction to scroll (e.g., 'down', 'up', 'left', 'right'). |
| pixels | string | The number of pixels to scroll. |
Response Structure
The method returns a Promise that resolves to a BrowserActionResponseData object with the following properties:
type(string): Always "scrollResponse".payload(object, optional): Contains the response data including:action(string, optional): The action that was performedsuccess(boolean, optional): Indicates if the scroll was successfulcontent(string, optional): Additional content informationviewport(object, optional): Updated viewport information after scrolling
eventId(string, optional): Event identifier for the scroll actionsuccess(boolean, optional): Indicates if the operation was successfulmessage(string, optional): A message with additional informationerror(string, optional): Error details if the operation failedmessageId(string, optional): A unique identifier for the messagethreadId(string, optional): The thread identifier
Example
// Navigate to a page with scrollable content
await codebolt.browser.goToPage("https://example.com");
// Wait for page to load
await new Promise(resolve => setTimeout(resolve, 2000));
// Scroll down the page by 100 pixels
const scrollResult = await codebolt.browser.scroll("down", "100");
console.log('✅ Scrolled:', scrollResult);
// Check if the scroll was successful
if (scrollResult.success) {
console.log('Page scrolled successfully');
} else {
console.error('Scroll failed:', scrollResult.error);
}
// You can also scroll in other directions
await codebolt.browser.scroll("up", "50");
await codebolt.browser.scroll("left", "100");
await codebolt.browser.scroll("right", "100");
Notes
- The
directionparameter accepts values: "up", "down", "left", "right" - The
pixelsparameter should be a string representing the number of pixels to scroll - The viewport information in the response reflects the new scroll position