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
uploadFile doesn't work with puppeteer.connect #4405
Comments
This should be fixed as of 532ae57 as we changed the underlying implementation to use |
awesome, thanks for the update @paullewis! |
Hello So using 3.0.1, we are still experiencing the exact same issue here, where we upload a file across the network (browser on a different machine). Any help on getting this to work? |
Thanks a lot for the tip @mathiasbynens, it was really helpful! For anyone facing issues uploading with puppeteer, here is the code I went with that finally worked const fileToUpload = {
name: 'myFileName',
content: fs.readFileSync('/file/path').toString(),
mimeType: 'text/plain', // This will depend on your case
}
await page.evaluate(async (fileToUpload) => {
//Create blob and file from file string
const b = new Blob([fileToUpload.content], { type: fileToUpload.mimeType })
const dt = new DataTransfer();
dt.items.add(new File([b], fileToUpload.name));
//Simulate drag and drop on your input field using DataTransfer class
ele = document.querySelector('input[type=file]')
ele.files = dt.files;
ele.dispatchEvent(new Event('input', { bubbles: true }));
ele.dispatchEvent(new Event('change', { bubbles: true }));
}, fileToUpload); I hope this helps someone, instead of spending days working with and around puppeteer file upload. However, @mathiasbynens do you have an idea of why the builtin calls (I see there is a CDP call in newer versions) in puppeteer don't work? It would be nice to understand why that happened. Thanks again for your help. |
Since puppeteer verifies that files are present on its local file-system, then this breaks Is it possible to make it more graceful? For instance, if it's a |
I'm facing similar issue. I'm developing an app using puppeteer with VSCode Remote-Containers and Remote-WSL feature. When developing on local environment, I want to watch how puppeteer controls Chrome, so I connect puppeteer from inside of container to Chrome on host using --remote-debugging-port option. Of course upload feature works fine if completed inside the container in headless mode. But, if puppeteer can upload using remote Chrome, it will be really useful for debug in my situation. |
This issue still occurs, and is inconvenient on working with browserless.io...
I think this solution is good, const browser = await puppeteer.connect({ browserWSEndpoint: 'ws://.....' });
const page = await browser.newPage();
const input = await page.$('input[type="file"]')
await input.uploadFileWithStream(fs.createReadStream('./this/will/upload/an/empty/file')) @jschfflr Hi, how you you think about the solution...? |
I would agree that we should somehow support uploading files on connected sessions too. Not sure though why the initial implementation got changed. Was that for performance reasons or for security reasons @mathiasbynens @paullewis? If we added a streaming version (which I like) I would expect to actually stream the files content though. While that's certainly possible, it would be a bit more involved though. I'd be happy to accept a PR for that as soons as I understand the rational behind the original change. |
@jschfflr I also tried to know the reason. This is just my note but I share it. #5655 seems to be a revert of #5196. Puppeteer 2.0 used Then #5196 is introduced in Puppeteer 2.1. However it brought some bugs. A quick fix #5369 is merged into Puppeteer 2.1.1 However Puppeteer 2.1.1 still don't have Then all changes are reverted... (in Puppeteer 3.0 #5655) Initial Playwright implementation had the same code (without Playwright still use the logic without |
…onnected via puppeteer.connect Issues: puppeteer#4405
Let's see if @mathiasbynens or @paullewis can fill in the blanks a bit here. |
Oh, this is quite old. This is fixed in #8472. |
Fixed! #8472 |
Steps to reproduce
Currently when used
inputElement.uploadFile
viapuppeteer.connect
, it uploads an empty file, as it doesn't exist on host machine. I believe this is a DevTools limitation and there's no possible workaround except uploading the file to remote puppeteer's host.What steps will reproduce the problem?
const page = await puppeteer.connect(/* ... */);
const input = await page.$('input[type="file"]');
await input.uploadFile('./this/will/upload/an/empty/file');
What is the expected result?
connect
.What happens instead?
Puppeteer silently uploads an empty payload.
The text was updated successfully, but these errors were encountered: