Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

add html download action

Naymul Islam3f6811387650
diff --git a/browser_use/controller/service.py b/browser_use/controller/service.py
index db37ad71b..b3fa0ffae 100644
--- a/browser_use/controller/service.py
+++ b/browser_use/controller/service.py
@@ -182,6 +182,30 @@ class Controller(Generic[Context]):
msg = f'📄 Extracted from page\n: {content}\n'
logger.info(msg)
return ActionResult(extracted_content=msg)
+
+ # HTML Download
+ @self.registry.action(
+ 'Download the full HTML content of the current page',
+ param_model=NoParamsAction,
+ )
+ async def download_html(_: NoParamsAction, browser: BrowserContext) -> ActionResult:
+ """Retrieves and returns the full HTML content of the current page"""
+ try:
+ page = await browser.get_current_page()
+ html_content = await page.content()
+ msg = f'📄 Page HTML content\n: {html_content}\n'
+ logger.info(f'Successfully retrieved page HTML: {msg}')
+ return ActionResult(
+ extracted_content=html_content, # Return raw HTML
+ is_done=True,
+ include_in_memory=False
+ )
+ except Exception as e:
+ logger.error(f'Failed to get HTML content: {str(e)}')
+ return ActionResult(
+ error=f'Error retrieving HTML: {str(e)}',
+ extracted_content=''
+ )
@self.registry.action(
'Scroll down the page by pixel amount - if no amount is specified, scroll down one page',