Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable download behavior #4197

Open
1 of 8 tasks
Tracked by #4233 ...
inancgumus opened this issue Apr 29, 2024 · 1 comment
Open
1 of 8 tasks
Tracked by #4233 ...

Configurable download behavior #4197

inancgumus opened this issue Apr 29, 2024 · 1 comment

Comments

@inancgumus
Copy link
Member

inancgumus commented Apr 29, 2024

What?

Add support to make download behavior configurable:

  • Downloading can be turned on or off.
  • Downloads are turned on by default in local runs.
  • Downloads are turned off in remote runs for security reasons.
  • User can set where to download files.
  • Create temporary directories if the download path is unset.

Why?

Turning off is required because some scripts hang when the file choosers open.

Turning on is required when users want to download files and see where the files are.

How?

Turning On and Off Downloads

We can control the download behavior using the existing BrowserContext.acceptDownloads option:

const context = await browser.newContext({
    acceptDownloads: false,
});

However, although we have the option implemented (set to false by default), we don't use it in the module code. So, the module's current behavior is always to accept downloads and open file choosers.

The goal of this issue is to use this option to control download behavior.

Other tools set this option to true by default. One advantage of keeping it false is that it lets us learn about user behavior. The disadvantage is that users would need to explicitly set it to true to make downloading in their scripts work. We'll set the option to true by default to match the general industry.

Setting the download path

We can let users where to save files using the downloadsPath option:

const context = await browser.newContext({
    acceptDownloads: true,
    downloadsPath: '/my/directory',
});

When set, files are downloaded into the directory. Otherwise, they're saved in a temporary directory.

CDP API

action := cdpbrowser.
	SetDownloadBehavior(/* configurable */).
	WithDownloadPath(/* configurable */).
	WithBrowserContextID(...)

Explanation:

  • SetDownloadBehaviorBehaviorDefault: Opens a file chooser by default. This is the browser module's current behavior even without calling SetDownloadBehavior.
  • SetDownloadBehaviorBehaviorAllow: Automatically downloads files to a user-specified folder. Other tools randomly pick a directory name if not specified. We'll follow suit.
  • SetDownloadBehaviorBehaviorDeny: Denies downloads. We'll set this based on the user's request or if the test run is on the cloud.

Tasks

Tasks

Preview Give feedback
  1. feature
    inancgumus

Related PR(s)/Issue(s)

#4233

@inancgumus inancgumus self-assigned this Apr 29, 2024
@inancgumus inancgumus changed the title page.on('download') Download.cancel May 6, 2024
@inancgumus inancgumus changed the title Download.cancel page.on('download').cancel() May 6, 2024
@inancgumus inancgumus removed their assignment May 24, 2024
@andrewslotin andrewslotin changed the title page.on('download').cancel() Allow skipping the file download dialog Sep 18, 2024
@inancgumus inancgumus mentioned this issue Jan 21, 2025
@inancgumus inancgumus changed the title Allow skipping the file download dialog Allow skipping file choosers Oct 17, 2024
@inancgumus inancgumus changed the title Allow skipping file choosers Dismiss file choosers Oct 17, 2024
@ankur22 ankur22 assigned ankur22 and unassigned ankur22 Oct 17, 2024
@inancgumus inancgumus changed the title Dismiss file choosers Configurable download behavior Oct 17, 2024
@inancgumus inancgumus self-assigned this Oct 17, 2024
@ankur22
Copy link
Contributor

ankur22 commented Oct 17, 2024

I like this new proposal where we're working with an existing field on browserContext 🙏

const context = await browser.newContext({
    acceptDownloads: false,
});

inancgumus referenced this issue Oct 29, 2024
I'm not yet sure if we should add this PR as it's a part of a bigger
functionality that we expect to have in k6 v0.56.

See the issue for more details:
https://github.com/grafana/xk6-browser/issues/1289
oleiade referenced this issue Nov 11, 2024
* Initialize v0.55.0 release notes

* Update release notes for browser 1448

* Update release notes for browser page.on generalization

* Update release notes for browser 1439

* Update release notes for browser 1461

* Update release notes for browser 1496

I'm not yet sure if we should add this PR as it's a part of a bigger
functionality that we expect to have in k6 v0.56.

See the issue for more details:
https://github.com/grafana/xk6-browser/issues/1289

* Replace issue 1461 with PR 1462

* release notes: webcrypto RSA support

* release notes: statsd output removal

* release notes: outputs changes

* Add browser related changes to release notes

* Remove template examples from release notes

* Add browser#1457 to release notes

* release notes: updates check recommendation

* Add initial page.on('metric') release note change

* Add issues to the page.on('metric') release note

* release notes: add TLA support section

* release notes: add tracing breaking change and future open ones

* auto-assigner changelog

* check recommendation apply feedback

* fixup! release notes: add tracing breaking change and future open ones

* Apply release notes clean-ups and fillers

* Address wrong formulation of tracing removal

* Update release notes/v0.55.0.md

Co-authored-by: Oleg Bespalov <[email protected]>

* Apply suggestions from code review

Co-authored-by: Ankur <[email protected]>

* Apply suggestions from code review

Co-authored-by: Ankur <[email protected]>

* Apply pull request review suggestions

* Update the page.on('metric') description

* Update release notes/v0.55.0.md

Co-authored-by: Ankur <[email protected]>

* Update page.on example as an expandable detail

* Align last sections format with template

* Update ControlOrMeta description

* Update wording of page.on example

* Apply pull request review suggestions

* Document #4017 bug fix

* Update release notes/v0.55.0.md

Co-authored-by: Mihail Stoykov <[email protected]>

* Bring minor improvement to #4009

---------

Co-authored-by: İnanç Gümüş <[email protected]>
Co-authored-by: Oleg Bespalov <[email protected]>
Co-authored-by: ankur22 <[email protected]>
Co-authored-by: Mihail Stoykov <[email protected]>
Co-authored-by: Mihail Stoykov <[email protected]>
@inancgumus inancgumus transferred this issue from grafana/xk6-browser Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants