Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix: postDataJSON with application/x-www-form-urlencoded; charset=UTF-8 (#29889)
Max Schmitt38fc74db7c24
diff --git a/packages/playwright-core/src/client/network.ts b/packages/playwright-core/src/client/network.tsindex 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<channels.RequestChannel> implements apreturn 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<string, string> = {};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.tsindex 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);