diff --git a/packages/playwright-core/src/client/network.ts b/packages/playwright-core/src/client/network.ts index 75cda8d207..4bd7698016 100644 --- a/packages/playwright-core/src/client/network.ts +++ b/packages/playwright-core/src/client/network.ts @@ -141,7 +141,7 @@ export class Request extends ChannelOwner implements ap return null; const contentType = this.headers()['content-type']; - if (contentType === 'application/x-www-form-urlencoded') { + if (contentType.includes('application/x-www-form-urlencoded')) { const entries: Record = {}; const parsed = new URLSearchParams(postData); for (const [k, v] of parsed.entries()) diff --git a/tests/page/page-network-request.spec.ts b/tests/page/page-network-request.spec.ts index 37eb1a20dd..624e36abfd 100644 --- a/tests/page/page-network-request.spec.ts +++ b/tests/page/page-network-request.spec.ts @@ -290,6 +290,20 @@ it('should parse the data if content-type is application/x-www-form-urlencoded', expect(request.postDataJSON()).toEqual({ 'foo': 'bar', 'baz': '123' }); }); +it('should parse the data if content-type is application/x-www-form-urlencoded; charset=UTF-8', async ({ page, server }) => { + it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/29872' }); + await page.goto(server.EMPTY_PAGE); + const requestPromise = page.waitForRequest('**/post'); + await page.evaluate(() => fetch('./post', { + method: 'POST', + headers: { + 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8', + }, + body: 'foo=bar&baz=123' + })); + expect((await requestPromise).postDataJSON()).toEqual({ 'foo': 'bar', 'baz': '123' }); +}); + it('should get |undefined| with postDataJSON() when there is no post data', async ({ page, server }) => { const response = await page.goto(server.EMPTY_PAGE); expect(response.request().postDataJSON()).toBe(null);