Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

jayozer
Copy link
Contributor

@jayozer jayozer commented Sep 1, 2025

…; disable local JS fetch
Summary: Ensures exactly one file is written and one FileDownloadedEvent emitted for a single user download in local sessions. Remote behavior unchanged.

Root Cause: Multiple dispatch paths and dual file writes (native + JS fetch) for the same download in browser_use/browser/watchdogs/downloads_watchdog.py. Polling fallback also appended directly to the session list.

Changes:
De‑dup by GUID: add a per‑download handled flag to avoid multiple FileDownloadedEvent emissions across progress/JS/polling.
Disable local JS fetch by default via a private guard so the browser’s native download is the single writer.
Centralize tracking via events: remove direct _downloaded_files append in polling; rely on BrowserSession.on_FileDownloadedEvent.

File changed: browser_use/browser/watchdogs/downloads_watchdog.py

Behavior Changes:
Local: one file on disk (no “(1)” suffix) and one FileDownloadedEvent.
Remote: unchanged.

How To Test:
Option A (example script): set GOOGLE_API_KEY, run python examples/features/download_file.py. Expect one file in downloads, single FileDownloadedEvent, and one unique entry in browser_session.downloaded_files.
Option B (clean home): macOS/Linux:
TMP_HOME=$(mktemp -d); mkdir -p "$TMP_HOME/Downloads"
HOME="$TMP_HOME" GOOGLE_API_KEY=YOUR_KEY python examples/features/download_file.py
ls -1 "$TMP_HOME/Downloads" → exactly one file, no “(1)”.

Open Questions:
Would you like an opt‑in BrowserProfile flag to re‑enable the local JS fetch path (default off) for special cases?
Are there environments where local Browser.downloadProgress often lacks filePath, requiring a longer polling fallback? If so, what timeout would you prefer?

Changelog: Fix duplicate downloads in local sessions by single-dispatch and preferring native download.

Fix status: Implemented in b14fef2.
Move CDP handlers to method scope (not inside try).
Keep tab-based indentation; align outer except.
Single-dispatch: guard duplicates via GUID handled flag; remove direct session mutation in polling; disable local JS fetch path by default.
ruff-format adjustments committed; lint + type-check pass locally.
CI note: The remaining failure is tests/ci/test_radio_buttons.py due to missing LLM API key in fork CI (401 from OpenAI). The test invokes an LLM and needs repo secrets, which aren’t exposed to forks. The downloads fix itself passes lint/format/type-check.
Request: Please re-run on maintainer CI (with secrets) or let me know if you prefer I add a small skip guard so this test skips when API keys are absent.


Summary by cubic

Prevents duplicate local downloads by enforcing single-dispatch and using the native browser download as the only writer. Local sessions now create one file and emit one FileDownloadedEvent; remote behavior is unchanged.

  • Bug Fixes
    • Deduplicate by download GUID with a handled flag across progress/JS/polling paths.
    • Disable local JS fetch by default so only the native download writes the file.
    • Remove direct _downloaded_files appends in polling; rely on FileDownloadedEvent.

@CLAassistant
Copy link

CLAassistant commented Sep 1, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

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

Choose a reason for hiding this comment

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

1 issue found across 1 file


Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Ask questions if you need clarification on any suggestion

React with 👍 or 👎 to teach cubic. You can also tag @cubic-dev-ai to give feedback, ask questions, or re-run the review.

@jayozer
Copy link
Contributor Author

jayozer commented Sep 1, 2025

Fixed in b14fef2:
download_progress_handler is now defined at the same scope as download_will_begin_handler (not nested).
Kept tab-based indentation, aligned the outer try/except.
Confirmed registration works and no NameError.
Also resolved ruff-format nits in this block.

@MagMueller
Copy link
Collaborator

@mertunsall

@MagMueller
Copy link
Collaborator

I merged it here #2989 does this fix it for you?

@MagMueller MagMueller closed this Sep 8, 2025
@jayozer
Copy link
Contributor Author

jayozer commented Sep 8, 2025

@MagMueller Yes, it fixed the issue. Thank you!

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.

3 participants