mirror of
https://github.com/browser-use/browser-use
synced 2026-05-13 17:56:35 +02:00
Implement the ability to generate executable Playwright scripts from an Agent's run history (`AgentHistoryList`). This introduces the `PlaywrightScriptGenerator` class which translates recorded agent actions (clicks, inputs, navigation, etc.) into a Python script using Playwright's async API. Key features: - Uses XPath selectors derived from the agent's interaction history. - Includes a robust helper function (`_try_locate_and_act`) with XPath prefix trimming for improved resilience on dynamic pages. - Handles sensitive data placeholders by mapping them to environment variables in the generated script. - Supports configuring the browser launch and context based on the original agent's `BrowserConfig` and `BrowserContextConfig`. - Activated by setting the `save_playwright_script_path` option in `AgentSettings`. Includes modifications to `Agent` service to trigger generation and `AgentHistoryList` view to add the saving method. Also adds a new example (`examples/features/playwright_script_generation.py`). This feature enables reliable replay of agent runs, automated testing, and scripting of repetitive tasks discovered by the agent.