Skip to content

fix(routeFromHAR, take 2): hack harRouter to merge set-cookie headers#38487

Merged
yury-s merged 4 commits intomicrosoft:mainfrom
yepitschunked:fix_multiple_setcookie
Feb 14, 2026
Merged

fix(routeFromHAR, take 2): hack harRouter to merge set-cookie headers#38487
yury-s merged 4 commits intomicrosoft:mainfrom
yepitschunked:fix_multiple_setcookie

Conversation

@yepitschunked
Copy link
Contributor

This was previously closed in #38255 due to inactivity. This PR has been updated with the feedback from @yury-s on the previous PR to avoid a bug with single set-cookie headers.

Following PR description is copied from the original:

Route.fulfill currently does not support multiple headers with the same name (#37342). There are workarounds when using this API directly (merging headers, tweaking the header name casing, etc.), but this is problematic for routeFromHAR, which depends on
this API internally. This patch adds special handling for set-cookie headers within harRouter to merge them into one header. There's some precedent for treating set-cookie specially at various places in the codebase (ex:

const sep = name.toLowerCase() === 'set-cookie' ? setCookieSeparator : separator;
,
function splitSetCookieHeader(headers: types.HeadersArray): types.HeadersArray {
), so I think this is okay.

Route.fulfill currently does not support multiple headers with the same
name (microsoft#37342). There are workarounds when using this API directly
(merging headers, tweaking the header name casing, etc.), but this is
problematic for routeFromHAR, which depends on
this API internally. This patch adds special handling for set-cookie
headers within harRouter to merge them into one header. There's some
precedent for treating set-cookie specially at various places in the
codebase (ex:
https://github.com/microsoft/playwright/blob/f54478a23e0daa450fe524905eabc8aabf6efb07/packages/playwright-core/src/utils/isomorphic/headers.ts#L29,
https://github.com/microsoft/playwright/blob/baeb065e9ea84502f347129a0b896a85d2a8dada/packages/playwright-core/src/server/chromium/crNetworkManager.ts#L675), so I think this is okay.
expect(await page2.evaluate(fetchFunction, { path: '/echo', body: '12' })).toBe('12');
});

it('should replay requests with multiple set-cookie headers properly', async ({ context, asset }) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this test is still necessary with the multi-cookie test below (seems like that one both records and replays a HAR)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove it and revert the manual changes to har-fulfill.har

expect(cookie2.split('; ').sort().join('; ')).toBe('first=foo');
});

it('should record multiple set-cookie headers', {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Skn0tt Skn0tt requested a review from yury-s December 9, 2025 07:20
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

expect(await page2.evaluate(fetchFunction, { path: '/echo', body: '12' })).toBe('12');
});

it('should replay requests with multiple set-cookie headers properly', async ({ context, asset }) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove it and revert the manual changes to har-fulfill.har

yepitschunked and others added 2 commits January 21, 2026 10:36
Co-authored-by: Yury Semikhatsky <yurys@chromium.org>
Signed-off-by: Victor Lin <125177+yepitschunked@users.noreply.github.com>
@yepitschunked
Copy link
Contributor Author

@yury-s took me a while due to the holidays - addressed your feedback on the tests

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert changes in this file and we'll merge this PR

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

Test results for "tests 1"

8 flaky ⚠️ [chromium-library] › library/beforeunload.spec.ts:130 › should support dismissing the dialog multiple times `@ubuntu-22.04-chromium-tip-of-tree`
⚠️ [chromium-library] › library/popup.spec.ts:258 › should not throw when click closes popup `@ubuntu-22.04-chromium-tip-of-tree`
⚠️ [chromium-library] › library/browsertype-connect.spec.ts:935 › run-server › socks proxy › should proxy based on the pattern `@chromium-ubuntu-22.04-node24`
⚠️ [chromium-library] › library/popup.spec.ts:258 › should not throw when click closes popup `@chromium-ubuntu-22.04-node22`
⚠️ [firefox-library] › library/inspector/cli-codegen-1.spec.ts:1082 › cli codegen › should not throw csp directive violation errors `@firefox-ubuntu-22.04-node20`
⚠️ [firefox-page] › page/page-wait-for-function.spec.ts:104 › should work with strict CSP policy `@firefox-ubuntu-22.04-node20`
⚠️ [webkit-page] › page/page-network-request.spec.ts:288 › should parse the data if content-type is application/x-www-form-urlencoded `@webkit-ubuntu-22.04-node20`
⚠️ [playwright-test] › ui-mode-test-attachments.spec.ts:81 › should contain string attachment `@windows-latest-node20`

34234 passed, 756 skipped


Merge workflow run.

@github-actions
Copy link
Contributor

Test results for "MCP"

10 failed
❌ [chromium] › mcp/cli-isolated.spec.ts:21 › should not save user data by default (in-memory mode) @mcp-ubuntu-latest
❌ [firefox] › mcp/cli-isolated.spec.ts:21 › should not save user data by default (in-memory mode) @mcp-ubuntu-latest
❌ [webkit] › mcp/cli-isolated.spec.ts:21 › should not save user data by default (in-memory mode) @mcp-ubuntu-latest
❌ [chromium] › mcp/cli-isolated.spec.ts:21 › should not save user data by default (in-memory mode) @mcp-windows-latest
❌ [firefox] › mcp/cli-isolated.spec.ts:21 › should not save user data by default (in-memory mode) @mcp-windows-latest
❌ [webkit] › mcp/cli-isolated.spec.ts:21 › should not save user data by default (in-memory mode) @mcp-windows-latest
❌ [msedge] › mcp/cli-isolated.spec.ts:21 › should not save user data by default (in-memory mode) @mcp-windows-latest
❌ [chromium] › mcp/cli-isolated.spec.ts:21 › should not save user data by default (in-memory mode) @mcp-macos-15
❌ [firefox] › mcp/cli-isolated.spec.ts:21 › should not save user data by default (in-memory mode) @mcp-macos-15
❌ [webkit] › mcp/cli-isolated.spec.ts:21 › should not save user data by default (in-memory mode) @mcp-macos-15

4678 passed, 135 skipped


Merge workflow run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants