Commit Graph

8176 Commits

Author SHA1 Message Date
MagellaX 93a2bddb9c Fix provider branch ordering in llm models 2025-11-28 13:27:23 +05:30
TR-3B a90c3a0455 Merge branch 'main' into feature/mistral-support 2025-11-28 13:23:43 +05:30
MagellaX 09a83c97a4 Fix Mistral pyright warnings and schema test 2025-11-28 13:21:19 +05:30
Mert Unsal 24dff6f428 allowing MUCH MORE with coordinates (#3676)
<!-- This is an auto-generated description by cubic. -->
## Summary by cubic
Adds precise coordinate-based scrolling via CDP gestures and updates
prompt templates to guide when to use coordinates. Also auto-sizes
screenshots for Claude and Gemini to improve coordinate scaling
accuracy.

- **New Features**
- Added ScrollAtCoordinateAction and ScrollAtCoordinateEvent using CDP
synthesizeScrollGesture.
- Scales coordinates and scroll deltas from LLM screenshot size to the
real viewport.
- Reworked scroll action: page = viewport height, removed index, memory
reports in px.
- Added Anthropic-specific system prompts and selection logic; prompts
now advise when to use coordinates.
- Auto-configured LLM screenshot sizes: Claude Sonnet 1400x850, Gemini
1024x720.

- **Refactors**
  - Shortened click action description.
  - History step label is now "step_{number}".
  - Included new Anthropic prompt files in packaging.

<sup>Written for commit 79df8fc818.
Summary will update automatically on new commits.</sup>

<!-- End of auto-generated description by cubic. -->
2025-11-27 23:44:06 -08:00
TR-3B 0b82aa7348 Merge branch 'main' into feature/mistral-support 2025-11-28 13:00:24 +05:30
MagellaX 5de9b99567 Add Mistral provider with schema optimizer and presets 2025-11-28 12:56:41 +05:30
Krishna 7fd4a38a2b Update quickstart.mdx 2025-11-27 20:41:36 -06:00
mertunsall 79df8fc818 hotfix 2025-11-27 15:03:48 -08:00
mertunsall 46cb1a0ae1 allowing MUCH MORE with coordinates 2025-11-27 14:48:23 -08:00
Mert Unsal 7f76e4f133 now newlines are executed well with send keys (#3675)
<!-- This is an auto-generated description by cubic. -->
## Summary by cubic
Fixes newline handling in SendKeys so Enter works reliably in forms and
text areas. Also increases typing timeouts and removes artificial delays
for faster, more reliable input.

- **Bug Fixes**
- Map '\n' and '\r' to Enter by dispatching rawKeyDown, char, and keyUp
(VK 13), ensuring correct submissions and line breaks.

- **Refactors**
- Increase default timeouts for TypeTextEvent and SendKeysEvent from 15s
to 60s.
  - Remove 18ms per-character delay in typing and send-keys loops.

<sup>Written for commit c4bb681058.
Summary will update automatically on new commits.</sup>

<!-- End of auto-generated description by cubic. -->
2025-11-26 18:14:57 -08:00
mertunsall c4bb681058 now newlines are executed well with send keys 2025-11-26 18:04:56 -08:00
Mert Unsal 8873194326 Copy profiles to temp for real browsers (fix #3329, #3301, #3184) (#3395)
[Chrome’s API was
updated](https://github.com/browser-use/browser-use/issues/1520) and no
longer permits direct access to user profiles.
To address this, the profile is now copied into a temporary directory
before launch. This prevents corruption or permission issues when using
persistent profiles. Tests have been updated accordingly to ensure
Chrome profiles are safely duplicated during runtime.

References:  
- https://github.com/browser-use/browser-use/issues/3329  
- https://github.com/browser-use/browser-use/issues/3301
- https://github.com/browser-use/browser-use/issues/3184  

**Follow-up**: If needed, adding an `update_profile` option to copy the
temporary profile back to the original directory after use could be
interesting?
2025-11-26 13:23:42 -08:00
Mert Unsal a048d97eab Merge branch 'main' into attempt-fix-real-browser 2025-11-26 13:22:22 -08:00
Mert Unsal 0cb6d7fc09 Add output format to Code Agent docs (#3505)
Added output format to Code Agent docs. Useful for llm code generation. 















<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Documented CodeAgent output format and return values so users can read
run() results and execution history. Added a new page and updated
parameter docs with current defaults and compatibility notes.

- **New Features**
- New Output Format page covering NotebookSession and CodeCell fields,
helper methods, task completion flags, and examples.
- Parameters doc updated: required/optional flags, defaults
(max_steps=100, use_vision=True), file_system, aliases (controller,
browser_session), and a return value section.
  - Added the new page to docs.json navigation.

<sup>Written for commit 0efd006527.
Summary will update automatically on new commits.</sup>

<!-- End of auto-generated description by cubic. -->
2025-11-26 13:21:28 -08:00
Mert Unsal 834cd85aae Merge branch 'main' into kalil/cu-docs 2025-11-26 13:19:54 -08:00
Mert Unsal c8d8c7e4b5 Add CodeAgentHistoryList for improved history management (#3510)
<!-- This is an auto-generated description by cubic. -->
## Summary by cubic
Introduce CodeAgentHistoryList to standardize CodeAgent history with a
clear, typed, eval-compatible API. Replaces ad-hoc mocks and exposes
history directly on NotebookSession.

- **New Features**
- Added CodeAgentHistoryList with AgentHistoryList-compatible methods
(final_result, is_done, errors, urls, screenshots, action_results,
model_actions, save_to_file).
- NotebookSession.history now returns CodeAgentHistoryList; session
stores _complete_history and _usage_summary.
  - run() persists history and usage into the session for later access.

- **Refactors**
- Removed DictToObject/MockAgentHistoryList; service.history now returns
CodeAgentHistoryList.
  - Centralized history logic in views.py and simplified service.py.

<sup>Written for commit 7851657ded.
Summary will update automatically on new commits.</sup>

<!-- End of auto-generated description by cubic. -->
2025-11-26 13:19:26 -08:00
Mert Unsal 0efd006527 Merge branch 'main' into kalil/cu-docs 2025-11-26 13:19:07 -08:00
Mert Unsal 7851657ded Merge branch 'main' into kalil0321/codeagent-api-improv 2025-11-26 13:18:06 -08:00
Mert Unsal d03d403f30 env var to disable version check (#3673)
<!-- This is an auto-generated description by cubic. -->
## Summary by cubic
Add an env var to control version checks at agent startup. Defaults to
true; set BROWSER_USE_VERSION_CHECK=false to skip the check and the
upgrade log.

- **New Features**
- Gate the latest-version lookup behind
CONFIG.BROWSER_USE_VERSION_CHECK.
- Document BROWSER_USE_VERSION_CHECK in .env.example with a short note.

<sup>Written for commit 9dc64f9b8b.
Summary will update automatically on new commits.</sup>

<!-- End of auto-generated description by cubic. -->
2025-11-26 13:08:04 -08:00
Mert Unsal 9dc64f9b8b Merge branch 'main' into mert/disable_version_check 2025-11-26 13:06:33 -08:00
mertunsall f98eb7a838 env var to disable version check 2025-11-26 13:06:03 -08:00
Mert Unsal 42bd2bbda4 Fix: Preserve in-use temporary user_data_dir during browser launch (#3638)
Previously, when browser launch succeeded after retry using a temporary
directory, the code immediately deleted ALL temporary directories
including the one actively being used by the running browser process.

The fix preserves the currently used temporary directory until browser
cleanup





<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Fixes a crash where a successful retry launch deleted the active
temporary user_data_dir, causing Chrome to write to a removed path. We
now keep the in-use temp profile until browser shutdown.

- **Bug Fixes**
  - Only remove unused temporary directories after a successful launch.
- Track and preserve the active user_data_dir for cleanup on browser
kill.

<sup>Written for commit 4a7334ae77.
Summary will update automatically on new commits.</sup>

<!-- End of auto-generated description by cubic. -->





<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Preserves the active temporary `user_data_dir` after a successful
launch, cleaning only unused temp dirs and deferring the in-use dir
cleanup to browser kill.
> 
> - **Watchdog
(`browser_use/browser/watchdogs/local_browser_watchdog.py`)**:
> - Only remove unused temporary `user_data_dir` directories after a
successful launch.
> - Identify the currently used directory and retain it in
`_temp_dirs_to_cleanup` (if temp) for cleanup on browser kill; otherwise
clear the list.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
4a7334ae77. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-11-26 12:49:55 -08:00
Mert Unsal bc332c2cf5 Merge branch 'main' into fix/temp-dir-cleanup-bug 2025-11-26 12:49:43 -08:00
Mert Unsal 6d2bb5b1a6 Update URL from localhost to 127.0.0.1 and fix typo (#3360)
<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Switched the CDP URL from localhost to 127.0.0.1 in the local browser
watchdog to prevent IPv4/IPv6 connection issues, and fixed the
apply_to_job instructions (“Make sure to delegate…”).

<sup>Written for commit ca2bed58fe.
Summary will update automatically on new commits.</sup>

<!-- End of auto-generated description by cubic. -->



<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Switches CDP URL from localhost to 127.0.0.1 and cleans up example
instructions.
> 
> - **Browser watchdog
(`browser_use/browser/watchdogs/local_browser_watchdog.py`)**:
> - Update CDP readiness check to use `http://127.0.0.1:{port}` instead
of `http://localhost:{port}` for both request and returned base
`cdp_url`.
> - **Examples (`examples/use-cases/apply_to_job.py`)**:
> - Minor instruction copy edit: fix capitalization/grammar in the
step-by-step plan note.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
ca2bed58fe. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-11-26 12:49:16 -08:00
Mert Unsal ca11fbb80e Merge branch 'main' into main 2025-11-26 12:49:07 -08:00
Mert Unsal 4a7334ae77 Merge branch 'main' into fix/temp-dir-cleanup-bug 2025-11-26 12:45:53 -08:00
Mert Unsal 61d03cbd7b Fix Screenshot Problems with wrong focus (#3672)
Also dont change focus outside of get_or_create_cdp_session
<!-- This is an auto-generated description by cubic. -->
## Summary by cubic
Restricts agent focus to page/tab targets via the session manager to
avoid iframes/workers. Screenshot capture validates the focused target
and falls back to a page target without changing focus; adds helpers to
inspect focus and page targets.

- **Bug Fixes**
- Gate focus updates to valid page/tab targets in SwitchTabEvent and
AgentFocusChangedEvent.
- Use get_or_create_cdp_session(..., focus=True) for focus changes;
remove direct agent_focus_target_id writes.
- ScreenshotWatchdog: capture only from page/tab targets; fallback to a
page target if focus is invalid; do not change focus (focus=False).

- **New Features**
  - get_focused_target(): returns the currently focused target.
- get_page_targets(): returns all page/tab targets, excluding
iframes/workers.

<sup>Written for commit 7e98622594.
Summary will update automatically on new commits.</sup>

<!-- End of auto-generated description by cubic. -->
2025-11-26 12:43:51 -08:00
mertunsall 7e98622594 Remove wrong log{ 2025-11-26 12:40:47 -08:00
Mert Unsal ca2bed58fe Merge branch 'main' into main 2025-11-26 12:36:02 -08:00
Mert Unsal cb21a1b70e Merge branch 'main' into mert/fix_screenshot_bug 2025-11-26 12:32:47 -08:00
mertunsall ce3d222f2a safety checks 2025-11-26 12:32:15 -08:00
mertunsall d7600603a2 dont change agent focus outside? 2025-11-26 12:25:40 -08:00
Mert Unsal 10affff92b new tab in headless respect window size (#3369)
tested locally and worked


    
<!-- This is an auto-generated description by cubic. -->
---

## Summary by cubic
Ensures newly focused tabs in headless mode apply the configured
viewport (width, height, device scale factor) so window size is
respected. Fixes inconsistent rendering when switching tabs.

- **Bug Fixes**
- On AgentFocusChangedEvent, call _cdp_set_viewport for the focused tab
via its target_id, with error handling and debug logs.

<!-- End of auto-generated description by cubic. -->

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Ensure newly focused tabs apply the configured viewport (width,
height, device scale factor) so window size is respected.
> 
> - **Browser session (CDP)**:
> - On `AgentFocusChangedEvent`, set viewport on the focused tab using
`_cdp_set_viewport` with `event.target_id`.
> - Includes debug logging and error handling for viewport application
in `browser_use/browser/session.py`.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
89990d360d. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2025-11-26 11:03:28 -08:00
Mert Unsal 89990d360d Merge branch 'main' into main 2025-11-26 11:02:10 -08:00
Mert Unsal d1dda5de60 Quick Hack allow passing Base URL to MCP Server (#3671) 2025-11-26 10:42:32 -08:00
mertunsall 839ef52d3e quick hack 2025-11-26 10:40:34 -08:00
Mert Unsal f0e3e658ff Fixes what https://github.com/browser-use/browser-use/pull/3114 tried to fix (#3670)
<!-- This is an auto-generated description by cubic. -->
## Summary by cubic
Pass authentication headers to CDPClient and the /json/version fetch so
remote browser connections succeed with services that require auth. Adds
tests to verify headers flow through connect() for both ws and http
paths.

- **Bug Fixes**
- Use BrowserProfile.headers as additional_headers when creating
CDPClient.
- Include headers in httpx GET to /json/version when resolving the
WebSocket URL.

<sup>Written for commit 885ec7cc6f.
Summary will update automatically on new commits.</sup>

<!-- End of auto-generated description by cubic. -->
2025-11-26 10:35:00 -08:00
Mert Unsal 885ec7cc6f Merge branch 'main' into mert/fix_more 2025-11-26 10:33:39 -08:00
mertunsall ad1c9b070e fix 2025-11-26 10:33:06 -08:00
Mert Unsal ec1b3a95d2 Improve demo mode (#3614)
<!-- This is an auto-generated description by cubic. -->
## Summary by cubic
Improve demo mode with a new in-browser panel and persistent logs, plus
a display option for full panel or a minimal “last action + memory”
overlay. Also removes step-start and completion-summary demo logs to
keep output clean.

- **New Features**
- Added demo panel script generator with two modes: full side panel and
bottom-right “last action + memory” view.
- New profile setting: demo_mode_display = 'full' | 'last' (default
'last').
- Demo overlay now registers on new pages/tabs and updates on
navigation; logs and final result persist across reloads.

<sup>Written for commit c951b94193.
Summary will update automatically on new commits.</sup>

<!-- End of auto-generated description by cubic. -->
2025-11-26 10:29:16 -08:00
Mert Unsal 81fe5c0573 Merge branch 'main' into kalil0321/demo-mode 2025-11-26 10:28:04 -08:00
Mert Unsal eb16d8b56b Increase screenshot event timeout to 15 seconds (#3669)
Increase the default timeout for `TIMEOUT_ScreenshotEvent` to 15
seconds.

---
[Slack
Thread](https://browser-use.slack.com/archives/D092QUQDC56/p1764178131486469?thread_ts=1764178131.486469&cid=D092QUQDC56)

<a
href="https://cursor.com/background-agent?bcId=bc-00392000-bb99-47f3-8645-18b5decb2dfc"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/open-in-cursor-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/open-in-cursor-light.svg"><img alt="Open in
Cursor"
src="https://cursor.com/open-in-cursor.svg"></picture></a>&nbsp;<a
href="https://cursor.com/agents?id=bc-00392000-bb99-47f3-8645-18b5decb2dfc"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/open-in-web-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/open-in-web-light.svg"><img alt="Open in Web"
src="https://cursor.com/open-in-web.svg"></picture></a>



<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Increased the default timeout for TIMEOUT_ScreenshotEvent from 8s to 15s
to reduce timeouts on slow pages and large captures. Improves
reliability for full-page screenshots and in variable network
conditions.

<sup>Written for commit 717845c4a7.
Summary will update automatically on new commits.</sup>

<!-- End of auto-generated description by cubic. -->
2025-11-26 09:33:05 -08:00
Cursor Agent 717845c4a7 Increase ScreenshotEvent timeout to 15 seconds
Co-authored-by: mailmertunsal <mailmertunsal@gmail.com>
2025-11-26 17:29:29 +00:00
Mert Unsal e0cc4c7684 fix: use default_factory for event_timeout to allow runtime env var c… (#3668)
### Problem

The `event_timeout` fields on all event classes were evaluated at
**module import time**, not at instance creation time. This meant that
environment variables like `TIMEOUT_TypeTextEvent` had to be set
**before** importing `browser_use`, making dynamic runtime configuration
impossible.

```python
# This didn't work:
import os
from browser_use.browser.events import TypeTextEvent

os.environ["TIMEOUT_TypeTextEvent"] = "60"  # Too late - already evaluated to 15.0
event = TypeTextEvent(...)
print(event.event_timeout)  # 15.0 ❌
```

### Solution

Changed all `event_timeout` field defaults from:
```python
event_timeout: float | None = _get_timeout('TIMEOUT_X', 15.0)
```

To:
```python
event_timeout: float | None = Field(default_factory=lambda: _get_timeout('TIMEOUT_X', 15.0))
```

Using `default_factory` defers the
[_get_timeout()](cci:1://file:///Users/tomergal/CascadeProjects/browser-use/browser_use/browser/events.py:15:0-42:15)
call until each event instance is created, allowing users to set timeout
environment variables at any point before creating events.

### After this fix

```python
import os
from browser_use.browser.events import TypeTextEvent

os.environ["TIMEOUT_TypeTextEvent"] = "60"
event = TypeTextEvent(...)
print(event.event_timeout)  # 60.0 ✅
```

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Make event timeouts read environment variables at runtime by deferring
evaluation to event instantiation. This enables dynamic configuration
(e.g., setting TIMEOUT_* after import) to take effect when creating
events.

- **Bug Fixes**
- Switched all event_timeout fields to use Field(default_factory=...) so
_get_timeout runs per instance.
- TIMEOUT_* env vars are now read when an event is created, not at
module import time.
  - Defaults remain unchanged if no env vars are set.

<sup>Written for commit 00462f9282.
Summary will update automatically on new commits.</sup>

<!-- End of auto-generated description by cubic. -->
2025-11-26 09:15:55 -08:00
tomerwave 00462f9282 fix: use default_factory for event_timeout to allow runtime env var configuration 2025-11-26 10:20:56 +02:00
Mert Unsal cd6763de87 Fix Structured Output with Enums (#3667)
<!-- This is an auto-generated description by cubic. -->
## Summary by cubic
Fixes enum serialization in structured outputs and preserves valid title
fields in JSON Schemas. This stabilizes agent action/result dumps and
Gemini function schema generation.

- **Bug Fixes**
- Serialize actions, results, and done payloads with mode='json' to
correctly handle enums (including nested values).
- In Gemini schema cleaning, only remove metadata-level title; keep
property title and allow it in required. Pass parent context to nested
items.
- Recursively process type values in schema optimization to resolve refs
nested under type.
- Keep Gemini schemas valid by inserting a placeholder when object
properties would be empty.

<sup>Written for commit 1c9a87b98f.
Summary will update automatically on new commits.</sup>

<!-- End of auto-generated description by cubic. -->
2025-11-25 13:44:41 -08:00
Mert Unsal 4d87e49e1f Merge branch 'main' into mert/structured_output 2025-11-25 13:43:55 -08:00
mertunsall 1c9a87b98f Fix more 2025-11-25 13:33:28 -08:00
mertunsall ed7cfa4ab2 fix title problem in schema as well as enum problems 2025-11-25 13:02:39 -08:00
Mert Unsal 4ced060bb4 exponential retries improved (#3666)
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Implements configurable exponential backoff with jitter for BrowserUse
and Google LLM clients and adds CI tests validating retry behavior.
> 
> - **LLM Clients**:
>   - **`browser_use/llm/browser_use/chat.py`**:
> - Add configurable retry loop with exponential backoff + jitter for
retryable HTTP/network errors (`429, 500, 502, 503, 504`, timeouts,
connect errors).
> - New params: `max_retries`, `retry_base_delay`, `retry_max_delay`;
refactor into `_make_request` and `_raise_http_error` helpers.
>     - Preserve structured output handling; tolerate `usage=None`.
>   - **`browser_use/llm/google/chat.py`**:
> - Add exponential backoff + jitter retry logic with configurable
settings and expanded retryable codes.
> - Update defaults (`max_retries=5`, retryable codes list) and logging.
> - **Tests**:
> - **`tests/ci/test_llm_retries.py`**: Add async tests covering 503/429
retries with backoff timing, timeout retries, and no-retry cases
(401/400).
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
84be050ed7. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Adds configurable exponential backoff with jitter to BrowserUse and
Google LLM clients to reduce transient failures (rate limits, 5xx,
timeouts). Includes CI tests that verify retry timing and non-retry
cases.

- **New Features**
- BrowserUse: Retries on 429/500/502/503/504 and timeout/connect errors;
new settings max_retries, retry_base_delay, retry_max_delay; jittered
backoff; clear 401/402 errors; handles usage=None.
- Google: Defaults to max_retries=5; retryable codes expanded to
429/500/502/503/504; jittered backoff with base/max delay.
- Tests: Cover 503 and 429 retries, timeouts, and no-retry for 401/400;
assert exponential timing and max-retries behavior.

- **Refactors**
- BrowserUse: Extracted _make_request and _raise_http_error for clearer
error handling and retry flow.

<sup>Written for commit 84be050ed7.
Summary will update automatically on new commits.</sup>

<!-- End of auto-generated description by cubic. -->
2025-11-25 11:24:12 -08:00