Commit Graph

83 Commits

Author SHA1 Message Date
Magnus Müller ad03ce5e32 Merge branch 'main' into codex/fix-url-negation-boundaries 2026-08-30 17:17:30 -07:00
Aniket Wagh 3c565af3e0 perf: keep bracket trimming linear in sanitize_url_candidate
The trimming loop counted brackets across the whole candidate on every
iteration, so a candidate ending in many unmatched brackets rescanned it
once per bracket. 50,000 trailing ')' took 0.9s, where the regex this
replaced was linear.

Count the four bracket characters once and decrement as characters are
trimmed, tracking the end index instead of reslicing. Same results, and
200,000 trailing ')' now takes 0.011s.
2026-08-28 09:50:05 +05:30
Aniket Wagh d33cc68f06 fix: keep balanced trailing brackets in URLs extracted from task text
sanitize_url_candidate() strips trailing prose punctuation so that
"Go to https://example.com/docs." does not navigate with the sentence's
period attached. It also stripped every trailing ) and ], including the
ones the URL opened itself, so a task like

    Summarize https://en.wikipedia.org/wiki/Python_(programming_language)

auto-navigated to .../Python_(programming_language and landed on the wrong
page. Wikipedia disambiguation links are the common case.

Whether the bracket belongs to the URL is decided by balance: a closing
bracket with a matching opener inside the candidate is part of the path,
while one the prose opened, as in "(see https://example.com/guide)", is not.
Strip trailing punctuation as before, and only drop a closing bracket when
the candidate has more of them than openers.

Fixes #5575
2026-08-28 09:50:05 +05:30
Lai Yujie fcf0b9229f Update browser_use/utils.py
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
2026-08-20 09:54:07 +08:00
JayLay0310 8e880168a9 fix(agent): match URL negations as whole words 2026-08-20 09:34:18 +08:00
Saurav Panda f4ab970cd2 Merge branch 'main' into fix/redact-cascade 2026-08-03 15:43:23 -07:00
GautamSharma99 ac15362576 fix(async): avoid re-raising task callback errors 2026-07-23 22:18:39 +05:30
Santh ef1a51d4f4 fix(utils): prevent redact_sensitive_string cascade corruption (#5135)
The iterative str.replace loop corrupts output when a shorter secret
is a substring of a <secret> placeholder tag written by an earlier
iteration (e.g. 'secret' inside '<secret>password</secret>').

Replace with a single-pass re.sub using a regex alternation of all
secret values (longest first). Each position in the input is consumed
at most once, so earlier replacements cannot be corrupted by later
ones.

Closes #5135
2026-07-13 06:17:12 -07:00
Gregor Žunič a75b950dc7 Fix prerelease version upgrade check 2026-06-08 13:35:20 -07:00
Magnus Müller 1474c60da1 Merge remote-tracking branch 'upstream/main' into magnus/browser-use-rust-core-integration
# Conflicts:
#	browser_use/__init__.py
#	browser_use/agent/service.py
#	browser_use/browser/watchdogs/downloads_watchdog.py
#	browser_use/code_use/utils.py
#	browser_use/llm/models.py
#	browser_use/tokens/service.py
#	browser_use/utils.py
2026-06-04 16:14:57 +00:00
Magnus Müller 91705e22b7 Sanitize direct-start URL candidates 2026-06-04 08:51:39 +00:00
Magnus Müller f644efbcad Record Rust eval Laminar summaries 2026-06-04 04:10:20 +00:00
Laith Weinberger 65f87b7fca fix sensitive_data redaction order to prevent substring leaks 2026-04-11 18:16:24 -04:00
BillionClaw 1147daef92 fix(utils): add option to disable SignalHandler for host app signal control
Add disabled parameter to SignalHandler class to allow opting out of
signal handling. This enables browser-use to be embedded in applications
like uvicorn/FastAPI that need to manage their own signal lifecycle.

Add enable_signal_handler parameter to Agent class (default True for
backward compatibility). When set to False, the Agent will not register
signal handlers, allowing the host application to control graceful
shutdown and signal handling.

Fixes #4385
2026-03-17 09:59:49 +08:00
hacking-racoon 38703d5ad7 perf: lazy import for openai and reportlab to reduce startup latency
- agent/views.py: Move RateLimitError import inside format_error() function
  to avoid loading openai SDK (~800ms) at module level
- llm/messages.py: Replace openai.BaseModel with pydantic.BaseModel directly
  to remove unnecessary openai dependency
- filesystem/file_system.py: Move reportlab imports inside sync_to_disk_sync()
  to avoid ~40ms startup cost when PDF generation is not used
- utils.py: Convert OpenAIBadRequestError and GroqBadRequestError to lazy
  loaders to avoid loading SDKs at module level

This improves import time for users who don't use OpenAI provider,
especially when using Anthropic, Google, or other providers.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 01:48:47 +09:00
mertunsall a64c82ef2c sanitize everything now 2025-11-14 11:13:57 -08:00
reformedot bc8407ac8d refactor: refine exception propagation in create_task_with_error_handling
- Introduced a variable to hold exceptions for re-raising outside the try-except block, ensuring proper propagation to the event loop.
- Updated comments for clarity on the exception handling process in background tasks.
2025-11-12 20:46:06 -08:00
reformedot e7b8f2987c refactor: improve exception handling in create_task_with_error_handling
- Updated the logging behavior for exceptions in background tasks to log at warning level and re-raise exceptions for better propagation to the event loop's exception handler.
- Enhanced clarity in comments regarding exception retrieval and handling.
2025-11-12 20:36:47 -08:00
reformedot 77d7f161fb refactor: enhance session management and error handling in BrowserSession
- Improved the `create_task_with_error_handling` function to allow for better exception logging and retrieval based on the `suppress_exceptions` parameter.
- Updated `SessionManager` to implement event-driven recovery for stale agent focus, replacing polling with efficient event handling.
- Refactored session retrieval methods to ensure focus validation and recovery are handled automatically.
- Enhanced logging for recovery processes and session management to provide clearer insights into state changes and errors.
- Adjusted various watchdogs to utilize the new session management methods, ensuring they correctly handle focus validation and session retrieval.
2025-11-12 19:42:24 -08:00
reformedot b4e9ffa984 refactor: implement error handling for asyncio tasks across various components
- Introduced a utility function `create_task_with_error_handling` to manage asyncio tasks with proper exception logging and suppression options.
- Updated multiple components, including `SessionManager`, `BrowserSession`, and various watchdogs, to utilize the new error handling mechanism for background tasks.
- Enhanced overall robustness of asynchronous operations by ensuring exceptions are logged and handled appropriately, improving maintainability and debugging capabilities.
2025-11-11 17:27:54 -08:00
Cursor Agent c4ed783a2b Refactor: Make version check async and use httpx
Co-authored-by: mamagnus00 <mamagnus00@gmail.com>
2025-09-19 04:12:48 +00:00
Gregor Žunič b5aebf0b03 shorten super long URLs 2025-09-05 15:42:41 -07:00
Nick Sweeting 95e9049faf Update browser_use/utils.py
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
2025-08-04 22:57:56 -04:00
Nick Sweeting 659c5145f6 more event-driven refactoring 2025-08-01 02:42:01 -07:00
Alezander9 87ab3c20fb address cubic comments 2025-07-30 17:31:22 -07:00
Alezander9 18876f222e add helper function for getting agent trace, remove references to deprecated gpt-4o 2025-07-29 18:11:56 -07:00
Nick Sweeting 48086d0cdd use retry decorator from bubus 2025-07-08 03:16:22 -07:00
Nick Sweeting 11b187576e fix multiprocess semaphore scope stale 2025-07-08 02:54:13 -07:00
Nick Sweeting b2a84b2296 fix tests and other improvements 2025-07-08 02:32:03 -07:00
Nick Sweeting 28ca11319c add overload warnings 2025-06-27 01:59:38 -07:00
Nick Sweeting 1415562d6e add portalocker multiprocess semaphore 2025-06-26 23:53:28 -07:00
Nick Sweeting 4b2d7c270b fix tests 2025-06-26 07:30:03 -07:00
Nick Sweeting fc075c0152 use retry decorator for locking and timeouts instead ofmanual logic 2025-06-26 07:07:13 -07:00
Gregor Žunič 7a10ae0c96 Squashed commit langchain to native 2025-06-24 12:26:55 +02:00
Nick Sweeting 6c695d0a42 more lint and hint fixes 2025-06-21 05:39:17 -07:00
Nick Sweeting 340bafdd29 move old tests to old folder 2025-06-21 04:47:46 -07:00
Nick Sweeting 3cf9f3410c fix config issues 2025-06-21 04:03:58 -07:00
Nick Sweeting f4b1987761 fixes 2025-06-21 03:43:37 -07:00
Nick Sweeting 6ede8842e5 Update browser_use/utils.py
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
2025-06-21 06:38:57 -04:00
Nick Sweeting 49e9fd4ff2 move env var config to utils file 2025-06-21 03:14:46 -07:00
Magnus Müller ad446f5769 Merge branch 'main' into mert/new_everything 2025-06-19 23:45:41 +02:00
Nick Sweeting 36c88b760c Consolidate sync related code (#2009) 2025-06-19 07:41:28 -07:00
Nick Sweeting 778536a3ce move all sync code into sync dir 2025-06-19 01:28:22 -07:00
Magnus Müller 0b6ebea431 Merge branch 'main' into mert/new_everything 2025-06-19 09:49:43 +02:00
Yasith Jayawardana e2e11966d3 Merge branch 'main' into typing-improvements 2025-06-18 21:20:47 -04:00
Nick Sweeting 474476f0ae switch to external bubus lib 2025-06-18 01:41:16 -07:00
mertunsall 0c34c399db Merge branch 'main' into mert/new_everything 2025-06-17 11:19:06 +02:00
yasithdev 8ea4b4c71a centralize playwright/patchwright imports, and update typing/checks to reduce lint errors 2025-06-16 22:57:20 -04:00
Nick Sweeting eb2807e779 fix unbound logger 2025-06-10 02:24:27 -07:00
Nick Sweeting 930a7aa4de use self.logger for timing log lines 2025-06-10 00:24:50 -07:00