Skip to content
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]: "setExtraHTTPHeaders" and "route" methods don't work for <a> download links #30656

Open
DeniDoman opened this issue May 3, 2024 · 1 comment

Comments

@DeniDoman
Copy link

DeniDoman commented May 3, 2024

Version

1.43.1

Steps to reproduce

  1. Clone my repo at https://github.com/denis-domanskii/playwright-download-intercept-issue
  2. npm install
  3. npm run test

Expected behavior

Two GET requests are intercepted, interceptionsCount variable equal 2

Actual behavior

Only one GET request is intercepted, interceptionsCount variable equal 1

Additional context

I want to test a web service protected by a token-based auth, so all requests must have an "X-Auth" header with a secret value.

Recently we added ability to download files, so I wrote an e2e test and it failed because when Playwright clicks on the <a href="/artifact.zip" download>Download link</a> link - it doesn't add the header, so server responds with 403 Forbidden and the test fails. I expect that the both setExtraHTTPHeaders and route methods should handle all requests, including download ones.

In my example repo, I am trying to intercept an archive download request:

test('Download intercept issue', async ({ page, context }) => {
  let interceptionsCount = 0;

  await context.route('https://denis-domanskii.github.io/playwright-download-intercept-issue/archive.zip', async route => {
    interceptionsCount++;
    await route.continue();
  });

  await page.goto('https://denis-domanskii.github.io/playwright-download-intercept-issue/');

  // FAIL: <a> tag with download is invisible for DevTools and Playwright intercept
  const downloadPromise1 = page.waitForEvent('download');
  await page.getByText("Download (with 'download' attr)").click();
  await downloadPromise1;

  // SUCCESS: <a> tag with download is visible for DevTools and Playwright intercept
  const downloadPromise2 = page.waitForEvent('download');
  await page.getByText("Download (without 'download' attr)").click();
  await downloadPromise2;

  expect(interceptionsCount).toBe(2);
});

As I can't provide logs from the server side with a proof that there were no the 'X-Auth' header, I added the interceptionsCount variable incrementing each time when a request to the zip archive is intercepted. So, it intercepted 1 times instead of 2 and the test fails.

context.setExtraHTTPHeaders() also doesn't work, I checked it using logs of my server - there were no added header too.

Environment

os: MacOS 14.2.1 (23C71)
npm: 10.2.4
node: v21.6.2
@playwright/test: 1.43.1
@DeniDoman
Copy link
Author

DeniDoman commented May 5, 2024

Ok, probably it's a Chrome issue, because I see the that even Chrome DevTools ignores the request having the download attribute:

  1. Visit the page https://denis-domanskii.github.io/playwright-download-intercept-issue/
  2. Open Chrome DevTools "Network" tab (make sure that you capturing all requests)
  3. Click the first button
  4. Click the second button

Expected: Two requests are shown in the Network tab
Observed: Only one request is shown in the Network tab

So, could you please confirm that it's a Chrome issue and there is no way to handle it on Playwright side?
Chromium issue is raised too: https://issues.chromium.org/issues/338842124

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

No branches or pull requests

2 participants