Fix page crash auto-recovery: detect tab crashes via CDP, reload page, inform LLM by Sarthak816 · Pull Request #5068 · browser-use/browser-use · GitHub
Skip to content

Fix page crash auto-recovery: detect tab crashes via CDP, reload page, inform LLM#5068

Open
Sarthak816 wants to merge 19 commits into
browser-use:mainfrom
Sarthak816:fix/page-crash-auto-recovery-5067
Open

Fix page crash auto-recovery: detect tab crashes via CDP, reload page, inform LLM#5068
Sarthak816 wants to merge 19 commits into
browser-use:mainfrom
Sarthak816:fix/page-crash-auto-recovery-5067

Conversation

@Sarthak816

@Sarthak816 Sarthak816 commented Jun 19, 2026

Copy link
Copy Markdown

Description

Fixes issue #5067 — when a browser page/tab crashes (e.g., due to memory exhaustion, WebGL context loss, or renderer process crash), the agent now automatically detects the crash, reloads the page, and informs the LLM about the recovery.

Fix: Page crash detection and auto-recovery via CDP

Problem: When a page tab crashed, no CDP crash handler was registered. The SessionManager handled the resulting detachedFromTarget event and recovered focus to another/new tab, but the agent got a blank page with no explanation — leading to confusing "element not found" errors and eventual timeout.

Fix: Three-layer solution:

  1. Crash Detection (session.py): Registered a Target.targetCrashed CDP event handler on the root client. When the agent's focus tab crashes, the target ID and URL are captured before SessionManager clears focus.

  2. Auto-Recovery (session.py): Added check_and_recover_from_crash() method that waits for SessionManager to finish focus recovery, then navigates back to the crashed page's previous URL if the recovered tab is a blank/new-tab page.

  3. LLM Context (agent/service.py): Injected an ActionResult with long_term_memory before each step's context preparation, so the LLM sees "The previous page tab crashed and has been auto-recovered. The page has been reloaded." instead of confusing silent failures.

Changes

File Change
browser_use/browser/session.py Added _crashed_target_ids, _crashed_target_url private attrs; registered targetCrashed CDP handler; added check_and_recover_from_crash() method
browser_use/agent/service.py Added crash recovery check in step() after captcha handling, injects crash context into LLM messages

Summary by cubic

Detects browser tab crashes via CDP, auto-reloads the previous URL, and tells the LLM about the recovery to avoid confusing failures. Also improves Windows startup stability, ollama stream/format handling with clearer JSON errors, and installer behavior to avoid PATH shadowing.

  • Bug Fixes

    • Detect tab crashes via CDP and auto-recover: capture the crashed URL, reload it after focus recovery when landing on a blank/new tab, inform the LLM, skip reload when the previous URL is unknown, and use TargetCrashedEvent to fix typing.
  • Stability

    • Windows startup: add backoff retries for httpx version fetch, prevent proxy leakage in aiohttp polling, fix TCPConnector reuse, and disable GPU in Windows headless to avoid renderer crashes.
    • ollama: strip and forward top-level params (format, stream) correctly, support stream=True async generator responses and forward stream when using output_format, allow overriding schema with ChatOllama.format, and provide clearer JSON validation errors.
    • Installers: avoid PATH shadowing by creating CLI wrappers in ~/.local/bin (and .cmd on Windows); fix Windows .exe detection, .cmd path separators, heredoc $@, and literal PATH checks.
    • Beta agent: warn when the agent completes with no LLM result to surface setup issues (e.g., missing BROWSER_USE_API_KEY or invalid model names).

Written for commit 24fd671. Summary will update on new commits.

Review in cubic

…dling

Filter out top-level Ollama API parameters (format, stream) from
ollama_options since they should be passed as top-level arguments
to client.chat(), not as model options. This fixes cases where
users pass format in ollama_options which is silently ignored.

Add _clean_options() method to strip these params and log a warning.
Handle pydantic ValidationError separately with a clearer message
that hints at truncated JSON issues with vision models.

Fixes browser-use#5017
Add a warning when the beta Agent SDK agent completes without
producing a result and without an error. This helps users debug
issues where the LLM failed to respond (e.g., missing or invalid
BROWSER_USE_API_KEY, unsupported model name, or network errors).

Previously the agent silently returned None with no indication
of what went wrong, making it very difficult to diagnose initial
setup failures.

Fixes browser-use#5025
Instead of adding the entire virtualenv bin directory ($HOME/.browser-use-env/bin)
to the user's PATH, create individual wrapper scripts in ~/.local/bin for each
CLI command (browser-use, bu, browseruse, browser, browser-use-tui).

This prevents the venv's Python and other executables from shadowing the
user's system Python, while still making the CLI commands available.

Fixes browser-use#5033

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 issues found across 8 files

Tip: instead of fixing issues one by one fix them all with cubic

Re-trigger cubic

Comment thread browser_use/browser/session.py
Comment thread browser_use/llm/ollama/chat.py
Comment thread browser_use/browser/session.py
Comment thread browser_use/skill_cli/install.sh Outdated
Comment thread browser_use/skill_cli/install.sh Outdated
…ery returns False for unknown URLs, Ollama format/stream forwarding, .exe wrapper mismatch, grep -qF for literal path matching

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread browser_use/llm/ollama/chat.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant