-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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] setInputFiles does fetch that fails due to CSP #632
Comments
Can you provide a small script that reproduces the problem? I tried and was unable to: const {chromium} = require('playwright');
chromium.launch().then(async browser => {
const [page] = await browser.defaultContext().pages();
await page.setContent(`<input type="file">`);
const input = await page.$('input');
await input.setInputFiles('index.js');
await browser.close();
}); |
I have tried the code and it works fine if the button is clickable but in my scenario the button is kind overlays by a label. If I do drop.click(); it fails so I tried drop.setInputFiles('pic.png') but this doesnt seem to work for me. Is it an open issue? |
Clickability should not affect |
Closing because we cannot repro this for a while. Feel free to reopen if this is still an issue. |
This error occurs when content security policy on document is enabled. Fix it by disabling CSP by setting bypassCSP to true in newContext method. |
Disabling CSP fixed it for me as well, thanks for the hint. (There should be a user-editable (possibly via PRs) FAQ section on playwright.dev where people can put their HOWTOs, tips & tricks and so on.) @JoelEinbinder @dgozman Is disabling CSP the only/right way to make file upload work in this case? Because disabling it may have side effects (e.g. on my page, after disabling CSP I get a cookie consent modal displayed). If disabling CSP should not be the right way and if you're still interested in a repro case, I could provide on. In my case, if CSP is not disabled, I get the following error message when setInputFiles (
|
You can send a PR editing documentation source, it will be reflected on playwright.dev. As for the fetch error, let me take a look. Disabling CSP is a big hammer, so I'd prefer another solution. |
@dgozman Thanks for pointing out the link to the documentation source. Also thanks for looking again into this error. I have sent you the repro URL via email. |
Hi, I am trying to upload a file but getting below error:
Error: Evaluation failed: TypeError: Failed to fetch
at playwright_evaluation_script:3:30
at Array.map ()
at playwright_evaluation_script:2:46
at CRExecutionContext.evaluate
Code:
const drop= await page.waitForSelector("//input[@type='file']");
await drop.setInputFiles('pic.png')
Also, the same was working with below Puppeteer code:
const drop= await page.waitForXPath("//slot/input[@type='file']");
await drop.uploadFile('pic.png');
The text was updated successfully, but these errors were encountered: