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
show example of complex validation
Nick Sweeting1079d8a4b9b2
diff --git a/docs/customize/custom-functions.mdx b/docs/customize/custom-functions.mdxindex bef01095b..e6e614d4e 100644--- a/docs/customize/custom-functions.mdx+++ b/docs/customize/custom-functions.mdx@@ -77,14 +77,19 @@ Using a pydantic model is helpful because it allows more flexibility and power t```python+from typing import Annotated+from pydantic import BaseModel, AfterValidator+from browser_use import ActionResult+class MyParams(BaseModel):field1: intfield2: str = 'default value'+ field3: Annotated[str, AfterValidator(lambda s: s.lower())] # example: enforce always lowercase@controller.action('My action', param_model=MyParams)-def my_action(params: MyParams, browser_session: BrowserSession) -> ActionResult:- await (await browser_session.get_current_page()).keyboard.type(params.field2)- return ActionResult(extracted_content=f"Processed #{params.field1}")+def my_action(params: MyParams, page: Page) -> ActionResult:+ await page.keyboard.type(params.field2)+ return ActionResult(extracted_content=f"Inputted {params} on {page.url}")```Any special framework-provided arguments (e.g. `page`) will be passed as separate positional arguments after `params`.