getHTML
codebolt.browser.getHTML(): Promise<HtmlReceived>
Retrieves the HTML content of the current page.
Response Structure
The method returns a Promise that resolves to a HtmlReceived
object with the following properties:
type
(string): Always "htmlReceived".html
(string, optional): The HTML content of the current pagecontent
(string, optional): Alternative property for the HTML contentsuccess
(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 the page
await codebolt.browser.goToPage("https://example.com");
// Wait for page to load
await new Promise(resolve => setTimeout(resolve, 2000));
// Retrieve the HTML content of the current page
const htmlResult = await codebolt.browser.getHTML();
console.log('✅ HTML retrieved:', {
success: htmlResult.success,
htmlLength: htmlResult.html ? htmlResult.html.length : 0
});
// Access the actual HTML content
if (htmlResult.success && htmlResult.html) {
console.log('HTML content:', htmlResult.html);
// Process the HTML as needed
} else {
console.error('Failed to retrieve HTML:', htmlResult.error);
}
Notes
- The HTML content includes the complete source code of the current page
- This is useful for parsing page structure, extracting specific elements, or analyzing page content
- The response may contain large amounts of data depending on the page size