From d1c9efd40b325c91a0b8b0c101213214f0ca5b2d Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Tue, 18 Aug 2026 11:58:56 -0700 Subject: [PATCH] test(credentials): httpCredentials should not override page's Authorization header References: https://github.com/microsoft/playwright/issues/42291 --- .../browsercontext-credentials.spec.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/library/browsercontext-credentials.spec.ts b/tests/library/browsercontext-credentials.spec.ts index 4713245ff90a3..e420cb467a568 100644 --- a/tests/library/browsercontext-credentials.spec.ts +++ b/tests/library/browsercontext-credentials.spec.ts @@ -227,3 +227,22 @@ it('should fail with correct credentials and mismatching port', async ({ browser expect(responseOrError.status()).toBe(401); await context.close(); }); + +it('should not override Authorization header set by the page', async ({ browser, server }) => { + server.setAuth('/empty.html', 'user', 'pass'); + server.setRoute('/echo-auth', (req, res) => { + res.end(req.headers['authorization'] || ''); + }); + const context = await browser.newContext({ + httpCredentials: { username: 'user', password: 'pass' } + }); + const page = await context.newPage(); + const response = await page.goto(server.EMPTY_PAGE); + expect(response!.status()).toBe(200); + const received = await page.evaluate(async () => { + const response = await fetch('/echo-auth', { headers: { 'Authorization': 'Bearer my-own-app-token' } }); + return await response.text(); + }); + expect(received).toBe('Bearer my-own-app-token'); + await context.close(); +});