-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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] [Chromium/WebKit] Request object does not contain postData for file/blob #6479
Comments
@mxschmitt is there a workaround for this? I was thinking of using something like const cdp = await context.newCDPSession(page);
let requestId;
cdp.on('Network.requestWillBeSent', req => {
requestId = req.requestId;
});
const result = await cdp.send('Network.getRequestPostData', { requestId: requestId });
console.info('result.postData', result.postData); but this doesn't work for me |
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! |
not sure if this would affect the fix but this reproduces for both |
Yep. It's apparently a known bug in the chrome DevTools protocol that we lack post data for mulitpart/files. |
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. |
Same for the JS version with Chromium and contentType application/json on PUT and POST. Works with Firefox for the same requests. |
I know that the cause is somewhat known, but I encountered this issue using the Python binding as well. |
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". |
See also #9648 (comment) for more cases where Chromium lacks post data. |
See #15853 for another repro. |
I also hit similar issue because of the CDP bug in Chromium. I'm using Ky which utilises Here's a test: import { test, expect } from '@playwright/test'
test('postDataJSON() works with cloned request', async ({ page }) => {
const [request] = await Promise.all([
page.waitForRequest('**/*'),
page.evaluate(async () => {
const request = new Request('https://test-post-data-json.com', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ test: 'test' })
})
// Chromium, Firefox and Webkit work with the original request: fetch(request).
// Firefox and Webkit also work with cloned request but Chromium fails:
fetch(request.clone())
})
])
expect(request.postDataJSON()).toEqual({ test: 'test' })
}) |
We noticed that some requests were failing when routed through our replay proxy, but succeed on a normal chrome instance. Further investigation found that there's a [known issue](microsoft/playwright#6479) where chrome doesn't record POST requests for some resource types (forms, pings, etc). Switch to a full fledged external proxy so we are able to capture requests 1:1 to how the destination server will see them.
Seeing the same issue with The only drawback is this proxy is certainly slower than Seems like there's nothing to do on the playwright side until the chromium ticket is merged upstream. Hoping for a fast solution however since this issue affects a wide swath of request types. |
A bit of a hack for ky users, you can use a hook to prevent ky from cloning responses :
|
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 sending a blob microsoft/playwright#6479. When adding support for a custom web vitals reporter it will be easier to assert the values sent by the reporter.
A pity that this critical bug is still not fixed for 17 months. It stops me from using Chromium in Playwright tests with post data requests (as data is missing on recipient side). Any idea how to ping Chromium folks to finally fix this issue? |
It seems that they are finally working on it: |
Seems to be fixed, at least my tests are passing now using 'chromium' (previously passed with 'firefox' only) |
I can confirm the
While firefox and webkit can pass the test shared above ( #6479 (comment) ) With the
|
I can confirm that the issue still exists for me on the latest stable versions of Chromium, just as halilemreozen mentioned. I think this chromium bug is more adequate: https://crbug.com/1058404. Please "Star" it so it gets more traction. |
@Meir017 I think you were painfully close to having a workaround identified 2 years ago! I think you were just missing the cdp call to enable the import { Protocol } from "playwright-core/types/protocol";
const client = await page.context().newCDPSession(page);
// https://chromedevtools.github.io/devtools-protocol/tot/Network/#method-enable
await client.send("Network.enable");
const handleNetworkRequest = async ({ requestId }: Protocol.Network.requestWillBeSentPayload) => {
const res = await client.send("Network.getRequestPostData", { requestId });
console.log("postData", res.postData);
};
// https://chromedevtools.github.io/devtools-protocol/tot/Network/#event-requestWillBeSent
client.on("Network.requestWillBeSent", handleNetworkRequest);
// remove listener when no longer needed; avoids errors from attempting to get postData
// for requests in a browser that has been closed
client.off("Network.requestWillBeSent", handleNetworkRequest); Notably, the |
@apeltz I'm rather hesitant to using the CDP directly as it's only for chromium, if this is supported now then I think playwright should be able to support this (and fix the failing tests) |
@Meir017 I totally agree with preferring the playwright api(s) 👍. The CDP use is just a workaround for now. |
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 My workaround for the second project is to use But i don't understand why is working on the first and not on the second project.... I'm surprise this issue have 2 years old ! |
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. |
Exactly what Im experiencing right now. So Im not sure what the hell is going on, but it seems that people solved this issues by using firefox instead of chromium. This is DEFINITELY a CDP issue, since i used CDP's own Fetch API to get the requests directly from chromium, instead of going through puppeteer and still it did not work.
|
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 also encountered the exact same situation with this issue. request.postData always returned null, and the reason was that the HTTP client library I was using, which was ky, executed a clone before sending the request. I checked that using native fetch instead of ky returned the postData with the correct payload. It's my workaround global.setup.ts import { test as setup } from '@playwright/test';
setup('mock Request.prototype.clone', async ({ page }) => {
await page.evaluate(() => {
Request.prototype.clone = function() {
return this;
}
});
}); playwright.config.ts import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './tests',
// ...
projects: [
{
name: 'setup',
testMatch: /global\\.setup\\.ts/,
},
{
name: 'my test',
use: { ...devices['Desktop Chrome'] },
dependencies: ['setup'],
},
]
}); |
Context:
System:
Binaries:
Languages:
npmPackages:
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:
Describe the bug
the
request.postData()
containsnull
in Chromium and WebKit. In Firefox it's filled.The text was updated successfully, but these errors were encountered: