-
Notifications
You must be signed in to change notification settings - Fork 539
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
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
db91b73
clicking on link
Skn0tt a198e9d
support individual files
Skn0tt 271fbd1
add pdf test
Skn0tt 6426ec5
fix tests
Skn0tt 37e6923
tests
Skn0tt 899bbad
one more
Skn0tt b050b5b
disable one more
Skn0tt e4417ff
Merge branch 'main' into download
Skn0tt d8a3b02
Merge branch 'main' into download
Skn0tt 8ac6d27
update readme
Skn0tt e603179
Merge branch 'streamable-http' into download
Skn0tt b54b6ce
Merge branch 'main' into download
Skn0tt b32c2e0
remove pdf test
Skn0tt a47e49b
disable tests
Skn0tt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,10 @@ export class Context { | |
this._modalStates = this._modalStates.filter(state => state !== modalState); | ||
} | ||
|
||
hasModalState(type: ModalState['type']) { | ||
return this._modalStates.some(state => state.type === type); | ||
} | ||
|
||
modalStatesMarkdown(): string[] { | ||
const result: string[] = ['### Modal state']; | ||
for (const state of this._modalStates) { | ||
|
@@ -340,6 +344,13 @@ export class Tab { | |
fileChooser: chooser, | ||
}, this); | ||
}); | ||
page.on('download', download => { | ||
this.context.setModalState({ | ||
type: 'download', | ||
description: `Download (${download.suggestedFilename()})`, | ||
download, | ||
}, this); | ||
}); | ||
page.on('dialog', dialog => this.context.dialogShown(this, dialog)); | ||
page.setDefaultNavigationTimeout(60000); | ||
page.setDefaultTimeout(5000); | ||
|
@@ -356,7 +367,13 @@ export class Tab { | |
} | ||
|
||
async navigate(url: string) { | ||
await this.page.goto(url, { waitUntil: 'domcontentloaded' }); | ||
try { | ||
await this.page.goto(url, { waitUntil: 'domcontentloaded' }); | ||
} catch (error) { | ||
if (error instanceof Error && error.message.includes('net::ERR_ABORTED') && this.context.hasModalState('download')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's be a very Chrome-centric view on the matter. |
||
return; | ||
} | ||
|
||
// Cap load event to 5 seconds, the page is operational at this point. | ||
await this.page.waitForLoadState('load', { timeout: 5000 }).catch(() => {}); | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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!