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

fix: prepare jsHandle.uploadFile for CDP Page.handleFileChooser removal #5196

Merged
merged 2 commits into from Dec 3, 2019

Conversation

mathiasbynens
Copy link
Member

https://chromium-review.googlesource.com/c/chromium/src/+/1935410 removes Page.handleFileChooser from the CDP. This patch prepares jsHandle.uploadFile for that change while preserving existing semantics as much as possible.

lib/JSHandle.js Outdated Show resolved Hide resolved
lib/JSHandle.js Outdated
for (let i = 0; i < filePaths.length; i++) {
const name = filePaths[i];
const content = fileContents[i];
const file = new File([content], name);
Copy link
Contributor

Choose a reason for hiding this comment

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

const result = await fetch(`data:${files[i].mimeType};base64,${files[i].content}`);
const file = new File([await result.blob()], files[i].name);

Copy link
Member Author

Choose a reason for hiding this comment

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

Where are you getting mimeType from? Are you suggesting we introduce a dependency on mime-types, or am I missing some trick?

UTF-8-decoding the input file could fail for binary files, and so we
now read the raw file buffer and base64-encode it. To base64-decode it
within the page context, we use the Fetch API in combination with a
data URL. This requires knowing the proper MIME type for the input
file, which we now figure out using the new mime-types dependency.
Copy link
Collaborator

@hanselfmu hanselfmu left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@hanselfmu hanselfmu left a comment

Choose a reason for hiding this comment

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

LGTM

@mathiasbynens mathiasbynens merged commit 6091a34 into master Dec 3, 2019
@mathiasbynens mathiasbynens deleted the cl-1935410 branch December 3, 2019 08:18
dt.items.add(file);
}
element.files = dt.files;
element.dispatchEvent(new Event('input', { bubbles: true }));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there any way we can avoid the fake event here?

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

Successfully merging this pull request may close these issues.

None yet

5 participants