getBrowserInfo
codebolt.browser.getBrowserInfo(): Promise<any>
Retrieves browser information like height, width, scroll position of the current page.
Response Structure
The method returns a Promise that resolves to a BrowserInfoResponse
object with the following properties:
type
(string): Always "getBrowserInfoResponse".payload
(object, optional): Contains the response data including:info
(object): Browser viewport information with the following properties:width
(number): Browser viewport width in pixelsheight
(number): Browser viewport height in pixelsdevicePixelRatio
(number): Device pixel ratioscrollX
(number): Horizontal scroll positionscrollY
(number): Vertical scroll positionpageYOffset
(number): Page Y offsetpageXOffset
(number): Page X offsetwindowWidth
(number): Window widthwindowHeight
(number): Window heightoffsetHeight
(number): Element offset heightscrollHeight
(number): Total scrollable height
success
(boolean, optional): Indicates if the operation was successfulcontent
(string, optional): Additional content informationviewport
(object, optional): Alternative viewport information
eventId
(string, optional): Event identifier for the 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
await codebolt.browser.goToPage("https://example.com");
// Wait for page to load
await new Promise(resolve => setTimeout(resolve, 2000));
// Get browser information
const browserInfoResult = await codebolt.browser.getBrowserInfo();
console.log('✅ Browser info:', browserInfoResult);
// The browser info contains viewport and scroll data
if (browserInfoResult.success && browserInfoResult.payload?.info) {
const info = browserInfoResult.payload.info;
console.log('Browser dimensions and scroll position:', {
width: info.width,
height: info.height,
scrollX: info.scrollX,
scrollY: info.scrollY,
scrollHeight: info.scrollHeight
});
} else {
console.error('Failed to get browser info:', browserInfoResult.error);
}
Notes
- The browser info provides comprehensive viewport and scroll information
- This is useful for responsive design testing, scroll position tracking, and viewport-based automation
- The response includes both current viewport dimensions and total page dimensions