Skip to content

fix(downloads): fire complete callbacks for remote-browser downloads - #5264

Merged
MagMueller merged 3 commits into
browser-use:mainfrom
sergioperezcheco:fix/remote-download-complete-callback
Aug 2, 2026
Merged

MagMueller merged 3 commits into
browser-use:mainfrom
sergioperezcheco:fix/remote-download-complete-callback

Conversation

@sergioperezcheco

@sergioperezcheco sergioperezcheco commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

When a file download finishes on a remote browser, DownloadsWatchdog receives the CDP downloadProgress event with state == "completed", but the remote branch of that handler only dispatched FileDownloadedEvent on the event bus. It never invoked the registered _download_complete_callbacks.

The local-browser branch calls those callbacks inside _track_download(), which is exactly what DefaultActionWatchdog._execute_click_with_download_detection waits on: its on_download_complete sets an asyncio.Event the click action is awaiting. So for remote browsers the click that triggered a download blocked until download_complete_timeout (30s by default) even though the file was already on disk, as reported in #5132.

This adds the complete-callback invocation to the remote branch, using the same complete_info shape _track_download already uses (guid, url, path, file_name, file_size, file_type, auto_download), placed right before the FileDownloadedEvent dispatch.

I included a regression test (tests/ci/test_remote_download_complete_callback.py) that registers a fake CDP client via attach_to_target, drives the captured downloadProgress(completed) handler, and asserts the on_complete callback fires with the expected filename. The test fails on the unpatched code and passes with this change.

I could not run the full repo test suite locally because dependency resolution needs network access that is unavailable in this environment, but the new test passes against an isolated venv and ruff is clean on both touched files.

Refs #5132.


Summary by cubic

Fixes remote-browser downloads not firing completion callbacks. Callbacks now run when CDP downloadProgress reports completed, so actions waiting on downloads no longer time out.

  • Bug Fixes

    • Call _download_complete_callbacks in the remote path before FileDownloadedEvent with the same payload as local; log callback errors at debug level.
    • Add regression tests (tests/ci/test_remote_download_complete_callback.py) that drive the CDP handler, assert the callback fires, and confirm the CDP cache is cleared.
  • Refactors

    • Apply ruff formatting to the new test file.

Written for commit 8168483. Summary will update on new commits.

Review in cubic

@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.

No issues found across 2 files

Re-trigger cubic

@sergioperezcheco
sergioperezcheco force-pushed the fix/remote-download-complete-callback branch 3 times, most recently from acb21a1 to a3e1507 Compare July 26, 2026 06:34
On a remote browser, the downloadProgress(completed) handler only dispatched FileDownloadedEvent on the event bus and never invoked the registered _download_complete_callbacks. The local branch does this inside _track_download(), so DefaultActionWatchdog._execute_click_with_download_detection waited on its on_download_complete asyncio.Event until the 30s timeout even though the download had finished.

Call the complete callbacks (with the same complete_info shape _track_download uses) right before dispatching the event in the remote branch. Adds a regression test that drives the registered downloadProgress handler and asserts the callback fires; the test fails on the unpatched code.
Fix code-style CI failure (model_construct call fits on one line).
@sergioperezcheco
sergioperezcheco force-pushed the fix/remote-download-complete-callback branch from a3e1507 to 26b9457 Compare July 28, 2026 01:12
@MagMueller
MagMueller merged commit ca9ba7b into browser-use:main Aug 2, 2026
99 checks passed
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.

2 participants