playwright: [BUG] [Chromium/WebKit] Request object does not contain postData for file/blob
Context:
System:
- OS: Windows 10 10.0.19043
Binaries:
- Node: 12.13.1 - C:\Program Files\nodejs\node.EXE
- Yarn: 1.19.1 - ~\AppData\Roaming\npm\yarn.CMD
- npm: 6.14.2 - C:\Program Files\nodejs\npm.CMD
Languages:
- Bash: 4.4.20 - C:\WINDOWS\system32\bash.EXE
npmPackages:
- playwright: ^1.10.0 => 1.10.0 / tip-of-tree
Code Snippet
Help us help you! Put down a short code snippet that illustrates your bug and that we can run and debug locally. For example:
const playwright = require('.');
(async () => {
const browser = await playwright.webkit.launch();
const page = await browser.newPage();
await page.goto('http://example.com');
const requestPromise = page.waitForRequest(() => true);
const [request] = await Promise.all([
page.waitForRequest("**/*"),
page.evaluate(() => {
var file = new File(['file-contents'], 'filename.txt');
fetch('/data', {
method: 'POST',
headers: {
'content-type': 'application/octet-stream'
},
body: file
});
})
])
console.info('request.method()', request.method());
console.info('request.url()', request.url());
console.info('request.headers()', request.headers());
console.info('request.postData()', request.postData());
})();
Describe the bug
the request.postData() contains null in Chromium and WebKit. In Firefox it’s filled.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 28
- Comments: 27 (7 by maintainers)
Links to this issue
Commits related to this issue
- update to the latest Playwright & workaround postData===null https://github.com/microsoft/playwright/issues/6479#issuecomment-1193105330 — committed to mitmplay/mitm-play by wharsojo 2 years ago
- First prototype of using external proxy We noticed that some requests were failing when routed through our replay proxy, but succeed on a normal chrome instance. Further investigation found that ther... — committed to piercefreeman/popdown by piercefreeman 2 years ago
- Send web vitals to Vercel analytics in app (#40669) Sends web vitals to Vercel analytics. My plan for the test was to assert the data sent by the client but there's a bug where it's always null when... — committed to vercel/next.js by deleted user 2 years ago
chromium bug is closed as Wontfix, https://bugs.chromium.org/p/chromium/issues/detail?id=1058404. Is there any way to route multipart/form-data requests and get not null postData? (using chrome/chromium)
I’m facing this issue, but not on all my playwright project.
I’ve 2 projects with e2e, both use chromium, and i mock request to get
postDataJson()On the first project is working fine, i get the value that i need. On the second project i get undifined, like the bug you describe here.My workaround for the second project is to use
firefoxand it’s working fine.But i don’t understand why is working on the first and not on the second project… The depenedencies are the same, the mock request to get
postDataJsonis the same.I’m surprise this issue have 2 years old !
The link above seems to indicate this is a problem in Chromium, not Playwright. However, if you follow the discussion details it does not seem like the Chromium folks “are on it”.
Same for the JS version with Chromium and contentType application/json on PUT and POST. Works with Firefox for the same requests.
It seems that they are finally working on it: https://bugs.chromium.org/p/chromium/issues/detail?id=1019710#c23 https://chromium.googlesource.com/chromium/src/+/2f4d40dfc9fbd14e0f105551fce94f428566a796
A bit of a hack for ky users, you can use a hook to prevent ky from cloning responses :
There must be some difference between your projects. From what I understood, problem is when you or libraries are using request.clone(). In that case, postData is empty and it’s a Chromium bug, not playwright. But Chromium has that bug since 2020, and who knows if they’ll ever fix it, so maybe PlayWright could introduce some workaround.
Facing the same issue. The postData is always null but in network tab its clear that the data exists. In my case it is normal json payload post request. I am using the java binding at the moment.
Thanks for filing! Short of using a proxy, I don’t think there are any good workarounds at this time. These look like bugs in chromium and our webkit. It might take some time to fix, but I’m on the case!