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

Upload file doesn't work because website's CSP declines data urls #5507

Closed
VikramTiwari opened this issue Mar 13, 2020 · 8 comments
Closed
Labels

Comments

@VikramTiwari
Copy link
Contributor

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 2.1.1
  • Platform / OS version: macOS
  • URLs (if applicable): hire.lever.co/candidates (not public)
  • Node.js version: 12.16.1

What steps will reproduce the problem?

Please include code that reproduces the issue.

  1. Try to upload a file using elementHandle.uploadFile
  2. It loads the file internally as a data URL before uploading the file
  3. Look at the website's console log where we see the CSP error

983029b6-b249-4e09-ba2d-32f6aa0a5163

What is the expected result?
File gets uploaded properly and is not blocked by CSP

I think this might be outside the scope of puppeteer team but I was wondering if there are ways to get around this. Thanks!

@VikramTiwari
Copy link
Contributor Author

VikramTiwari commented Mar 13, 2020

For folks coming to this, you can use DOM.setFileInputFiles as a possible strategy. Though I would like to see puppeteer support that through it's methods rather than converting the file to data URL.

@mathiasbynens
Copy link
Member

We could essentially revert 6091a34 and continue to use DOM.setFileInputFiles like before. The other CDP changes w.r.t. file uploads did not need the changes in 6091a34 after all.

@VikramTiwari
Copy link
Contributor Author

VikramTiwari commented Mar 13, 2020

I think that would be a good idea. A lot of issues have happened since that I think can be attributed to this change.

Also, I understand the commit message but I am unable to understand where is that case applicable. Was this causing issues when doing i18n input fields or something similar?

@VikramTiwari
Copy link
Contributor Author

I am also very curious to understand why page.setBypassCSP didn't work for this.

@VikramTiwari
Copy link
Contributor Author

Hey @sivasait-opex Here's a sample for using CDP for animations. https://github.com/puppeteer/puppeteer/blob/v2.1.1/docs/api.md#class-cdpsession

@VikramTiwari
Copy link
Contributor Author

Sorry, the error is pretty self explanatory. You should be able to figure out more from the error message.

@mathiasbynens
Copy link
Member

#5654

@paullewis
Copy link
Contributor

This should be fixed as of 532ae57 since we use DOM.setFileInputFiles internally again.

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

No branches or pull requests

3 participants