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

[Bug]: Can't upload files when puppeteering a remote browser #8470

Closed
codr1 opened this issue Jun 3, 2022 · 0 comments · Fixed by #8472
Closed

[Bug]: Can't upload files when puppeteering a remote browser #8470

codr1 opened this issue Jun 3, 2022 · 0 comments · Fixed by #8472
Labels

Comments

@codr1
Copy link

codr1 commented Jun 3, 2022

Bug description

Steps to reproduce the problem:

  1. Connect to a remote browser that does not share the file system with environment executing the script (could be in a container or another machines)
  2. Try to upload a file using fileChooser.accpet
  3. Fail.

This seems to be due the following code in /puppeteer/lib/cjs/puppeteer/common/JSHandle.js
uploadFile()
.
.
// Locate all files and confirm that they exist.
const files = await Promise.all(filePaths.map(async (filePath) => {
const resolvedPath = path.resolve(filePath);
try {
await fs.promises.access(resolvedPath, fs.constants.R_OK);
}
catch (error) {
if (error.code === 'ENOENT')
throw new Error(${filePath} does not exist or is not readable);
}
return resolvedPath;
}));

This code seems to be trying to access the local file system of where the Puppeteer script is running to determine if the files are present. Since the browser is running on a different file system this does not go well.
There should be some way to tell puppeteer that we are on a remote system and can't just use fs.
Commenting this code out seems to work.

Puppeteer version

12.0.1

Node.js version

16.13

npm version

8.5.0

What operating system are you seeing the problem on?

Linux

Relevant log output

Error: C:\Users\vess\Downloads\download.csv does not exist or is not readable
    at /home/vess/dev/addon-puppeteer/node_modules/puppeteer/lib/cjs/puppeteer/common/JSHandle.js:531:27
    at async Promise.all (index 0)
    at async ElementHandle.uploadFile (/home/vess/dev/addon-puppeteer/node_modules/puppeteer/lib/cjs/puppeteer/common/JSHandle.js:524:23)
    at async FileChooser.accept (/home/vess/dev/addon-puppeteer/node_modules/puppeteer/lib/cjs/puppeteer/common/FileChooser.js:61:9)
    at async PageController.uploadFile (/home/vess/dev/addon-puppeteer/dist/page/navigate.controller.js:416:13)
    at async /home/vess/dev/addon-puppeteer/node_modules/@nestjs/core/router/router-execution-context.js:46:28
    at async /home/vess/dev/addon-puppeteer/node_modules/@nestjs/core/router/router-proxy.js:9:17
@codr1 codr1 added the bug label Jun 3, 2022
@jrandolf jrandolf linked a pull request Jun 3, 2022 that will close this issue
@jrandolf jrandolf removed a link to a pull request Jun 3, 2022
@jrandolf jrandolf linked a pull request Jun 3, 2022 that will close this issue
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 a pull request may close this issue.

1 participant