Skip to content

feat: browser_file_download #209

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

Closed
wants to merge 14 commits into from
Closed

feat: browser_file_download #209

wants to merge 14 commits into from

Conversation

Skn0tt
Copy link
Member

@Skn0tt Skn0tt commented Apr 17, 2025

Resolves #154

@Skn0tt Skn0tt requested review from pavelfeldman and Copilot April 17, 2025 10:01
@Skn0tt Skn0tt self-assigned this Apr 17, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for a new browser file download tool, alongside accompanying tests and updated type definitions. Key changes include:

  • Introducing a TestServer class to facilitate serving files during tests.
  • Adding new tests for browser file download functionality, including both HTML and PDF links.
  • Extending the tool definitions and context handling to support a download modal state.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/fixtures.ts Introduces a TestServer class for managing a local HTTP server.
tests/files.spec.ts Adds tests verifying browser file download behavior.
src/tools/tool.ts Updates modal state types to include download state.
src/tools/files.ts Implements the downloadFile tool and its schema for file downloads.
src/context.ts Adds modal state tracking and handling for download events.
Comments suppressed due to low confidence (1)

tests/fixtures.ts:28

  • [nitpick] Consider renaming the instance property 'PREFIX' to 'prefix' to indicate that it is not a constant.
PREFIX: string;

try {
await this.page.goto(url, { waitUntil: 'domcontentloaded' });
} catch (error) {
if (error instanceof Error && error.message.includes('net::ERR_ABORTED') && this.context.hasModalState('download'))
Copy link
Member

Choose a reason for hiding this comment

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

That's be a very Chrome-centric view on the matter.

@@ -293,6 +297,13 @@ export class Tab {
fileChooser: chooser,
}, this);
});
page.on('download', download => {
this.context.setModalState({
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure this is a modal state we'll be requiring to clear. Sounds to me like downloads is more of resources, so maybe just tell user once that download took place and teach it to list the downloads as a tool?

I.e. let's just save it here!

@Skn0tt
Copy link
Member Author

Skn0tt commented Apr 30, 2025

Summary from offline discussion:

  • similar to how a browser starts downloading files without user approval, we can do the same here
  • for bigger files, we'll need some sort of a "downloading" state. out of scope for now, we expect most users of this to be on fast connections and to be downloading small files
  • for detecting downloads in response to a navigation, checks on error message aren't good. we can check if playwright-core can detect this better.

@Skn0tt Skn0tt closed this Apr 30, 2025
@jmmfcoutinho
Copy link

jmmfcoutinho commented Apr 30, 2025

Hi!
Is this PR closed without any merge? Do you have any estimate when the browser_download feature will be available?

@Skn0tt
Copy link
Member Author

Skn0tt commented May 2, 2025

don't worry José, we're continuing work in #310 :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants