screenshot
codebolt.browser.screenshot(): Promise<BrowserScreenshotResponse>
Takes a screenshot of the current page.
Response Structure
The method returns a Promise that resolves to a BrowserScreenshotResponse
object with the following properties:
Response Properties:
type
: Always "screenshotResponse"payload
: Optional object containing the response datascreenshot
: Base64 encoded image data of the screenshotfullPage
: Optional boolean indicating if it's a full page screenshotsuccess
: Optional boolean indicating if the operation was successfulcontent
: Optional string with additional content informationviewport
: Optional viewport information object
eventId
: Optional string containing the event identifiersuccess
: Optional boolean indicating if the operation was successfulmessage
: Optional string with additional informationerror
: Optional string containing error details if the operation failedmessageId
: Optional unique identifier for the messagethreadId
: Optional thread identifier
Example
// Navigate to the page you want to capture
await codebolt.browser.goToPage("https://example.com");
// Wait for page to load completely
await new Promise(resolve => setTimeout(resolve, 2000));
// Take a screenshot of the current page
const screenshotResult = await codebolt.browser.screenshot();
console.log('✅ Screenshot taken:', screenshotResult);
console.log('Screenshot data available:', !!screenshotResult?.payload?.screenshot);
Explanation
The codebolt.browser.screenshot()
function captures a screenshot of the current page displayed in the browser. This function returns a promise that resolves with the screenshot data. The screenshot includes the visible portion of the webpage as it appears in the browser viewport. This function is helpful for various purposes such as visual verification, debugging, automated testing, generating documentation, or creating visual records of web pages during automation workflows.