Skip to content

New Feature: Config download behavior (#13309)#3232

Closed
kblok wants to merge 17 commits intomasterfrom
implement-upstream-change-13309
Closed

New Feature: Config download behavior (#13309)#3232
kblok wants to merge 17 commits intomasterfrom
implement-upstream-change-13309

Conversation

@kblok
Copy link
Copy Markdown
Member

@kblok kblok commented Feb 24, 2026

Implements changes from puppeteer/puppeteer#13309

Closes #2828

Add ability to configure download behavior on launch/connect and on
creation of new browser contexts via BrowserContextOptions.DownloadBehavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kblok kblok closed this Feb 24, 2026
@kblok kblok reopened this Feb 24, 2026
@kblok kblok closed this Feb 24, 2026
@kblok kblok reopened this Feb 24, 2026
@kblok kblok closed this Feb 25, 2026
@kblok kblok reopened this Feb 25, 2026
kblok and others added 16 commits February 25, 2026 10:22
The 1000ms timeout was too tight for Windows CI runners. Use 10s for
the success case and keep 1s for the deny case (which expects timeout).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The download test fails on all Windows CI configurations. The Chrome
version used (145.0.7632.77) may have a bug with Browser.setDownloadBehavior
on Windows that was fixed in the upstream version (145.0.7632.117).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Temporary diagnostics to understand why the download test fails on Windows:
- Listen for CDP download events
- List files in download directory after click
- Check default Downloads folder
- Additional CDP session to enable download events

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Browser.setDownloadBehavior with browserContextId doesn't reliably
apply to new pages on Windows. Re-send it through the page's CDP
session after page creation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The CreateCDPSessionAsync approach was causing flakiness on Windows
due to timing issues. Sending directly through Connection without
browserContextId is simpler and more reliable.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… context

The request type was missing from SystemTextJsonSerializationContext,
causing the DownloadPolicy enum to not serialize correctly (e.g. "Allow"
instead of "allow"). This was the root cause of Windows download test
failures. Removed the workaround of re-sending download behavior on
page creation since it's no longer needed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
On Windows, Chrome requires eventsEnabled=true for download behavior
to be properly applied to new pages in a browser context.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
On Windows, Browser.setDownloadBehavior with browserContextId alone
doesn't reliably apply to newly created pages. Send it again through
the page's existing Client session (no new CDP session overhead)
with eventsEnabled=true and without browserContextId.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Change BrowserSetDownloadBehaviorRequest.Behavior from DownloadPolicy
enum to string, using ToValueString() to convert. This ensures the
value is always serialized as lowercase "allow"/"deny" regardless of
how System.Text.Json handles enum converters on object-typed params.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…avior

Replicate exactly what was proven to work on Windows: create a new
CDP session from the page and send Browser.setDownloadBehavior using
an anonymous object (avoiding any potential serialization issues with
typed request classes).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Log CDP response from setDownloadBehavior
- Log download events (downloadWillBegin, downloadProgress)
- List files in download dir after 3s delay
- Check default Downloads folder
- Log browser version
- Send extra setDownloadBehavior through CDP session

This will help understand why downloads fail on Windows CI.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
On Windows, Browser.setDownloadBehavior with browserContextId alone
does not reliably apply to new pages. Re-send through a CDP session
created from the page (without browserContextId, with eventsEnabled)
to ensure downloads work cross-platform. Remove diagnostic test code.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The CreateCDPSessionAsync call must happen AFTER CreatePageInContextAsync
returns (page fully initialized), not inside it. Move the per-page
download behavior setup from CdpBrowser.CreatePageInContextAsync to
CdpBrowserContext.NewPageAsync to match the timing that works on Windows.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use the page's existing Client session instead of creating a new CDP
session. Send with an anonymous object to ensure correct serialization
via the session. This avoids CreateCDPSessionAsync overhead and
potential timing issues on Windows.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
On Windows, the page target is not fully ready immediately after creation.
Add Task.Delay(100) before CreateCDPSessionAsync to allow pending async
operations to complete. Also use TempDirectory helper in tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace typed BrowserSetDownloadBehaviorRequest with anonymous object
to match upstream JavaScript behavior. Remove per-page download behavior
workaround in NewPageAsync as context-level setup is sufficient.
Clean up unused import in CdpBrowser.cs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kblok kblok closed this Mar 3, 2026
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.

feat: config download behavior

1 participant