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
Conversation
https://chromium-review.googlesource.com/c/chromium/src/+/1935410 removes Page.handleFileChooser from the CDP.
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); |
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.
const result = await fetch(`data:${files[i].mimeType};base64,${files[i].content}`);
const file = new File([await result.blob()], files[i].name);
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.
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.
ea887d0
to
e7dcfeb
Compare
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.
LGTM
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.
LGTM
dt.items.add(file); | ||
} | ||
element.files = dt.files; | ||
element.dispatchEvent(new Event('input', { bubbles: true })); |
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.
Is there any way we can avoid the fake event here?
https://chromium-review.googlesource.com/c/chromium/src/+/1935410 removes
Page.handleFileChooser
from the CDP. This patch preparesjsHandle.uploadFile
for that change while preserving existing semantics as much as possible.