getSnapShot
codebolt.browser.getSnapShot(): Promise<any>Retrieves a snapshot of the current page.
Response Structure
The method returns a Promise that resolves to a BrowserSnapshotResponse object with the following properties:
type(string): Always "getSnapShotResponse".payload(object, optional): Contains the response data including:tree(object): DOM tree structure with the following properties:strings(array): Array of strings used in the DOM treedocuments(array): Array of document objects containing:nodes(object): Node information including:backendNodeId(array): Backend node identifiersattributes(array): Element attributes with name/value pairsnodeValue(array): Node valuesparentIndex(array): Parent node indicesnodeType(array): Node typesnodeName(array): Node namesisClickable(object): Clickable element informationtextValue(object): Text content valuesinputValue(object): Input field valuesinputChecked(object): Checkbox/radio button states
success(boolean, optional): Indicates if the operation was successfulcontent(string, optional): Additional content informationviewport(object, optional): 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 a snapshot of the current page
const snapshotResult = await codebolt.browser.getSnapShot();
console.log('✅ Snapshot taken:', snapshotResult);
// The snapshot contains comprehensive page state information
if (snapshotResult.success && snapshotResult.payload?.tree) {
const tree = snapshotResult.payload.tree;
console.log('Snapshot data available for analysis:', {
documentsCount: tree.documents?.length || 0,
stringsCount: tree.strings?.length || 0,
hasNodeData: !!tree.documents?.[0]?.nodes
});
// Process the snapshot data as needed
} else {
console.error('Failed to get snapshot:', snapshotResult.error);
}
Notes
- The snapshot provides a complete structural representation of the page's DOM
- This is useful for page analysis, element detection, and automated testing
- The tree structure includes element hierarchy, attributes, and interactive states
- The response contains detailed information about clickable elements and input values