Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
added feature to save webpage as PDF to given path
Anish Hiranandani8ccde1910339
diff --git a/browser_use/controller/service.py b/browser_use/controller/service.pyindex cf468f287..7005bcb79 100644--- a/browser_use/controller/service.py+++ b/browser_use/controller/service.py@@ -22,6 +22,7 @@ from browser_use.controller.views import (OpenTabAction,ScrollAction,SearchGoogleAction,+ SavePDFAction,SendKeysAction,SwitchTabAction,)@@ -164,6 +165,20 @@ class Controller(Generic[Context]):logger.info(msg)logger.debug(f'Element xpath: {element_node.xpath}')return ActionResult(extracted_content=msg, include_in_memory=True)++ # Save PDF+ @self.registry.action(+ 'Save the current page as a PDF file',+ param_model=SavePDFAction,+ )+ async def save_pdf(params: SavePDFAction, browser: BrowserContext):+ page = await browser.get_current_page()+ await page.emulate_media(params.media_type)+ await page.pdf(path=params.file_name, format='A4')++ msg = f"Saving page with URL {page.url} as PDF to {params.file_path}"+ logger.info(msg)+ return ActionResult(extracted_content=msg, include_in_memory=True)# Tab Management Actions@self.registry.action('Switch tab', param_model=SwitchTabAction)diff --git a/browser_use/controller/views.py b/browser_use/controller/views.pyindex 82995c9e3..e2cde89e6 100644--- a/browser_use/controller/views.py+++ b/browser_use/controller/views.py@@ -1,4 +1,4 @@-from typing import Optional+from typing import Optional, Literalfrom pydantic import BaseModel, model_validator@@ -48,6 +48,11 @@ class ExtractPageContentAction(BaseModel):value: str+class SavePDFAction(BaseModel):+ file_path: str+ media_type: Literal['screen', 'print'] = 'screen'++class NoParamsAction(BaseModel):"""Accepts absolutely anything in the incoming data