puppeteer / puppeteer

JavaScript API for Chrome and Firefox
https://pptr.dev
Apache License 2.0
88.69k stars 9.07k forks source link

[Bug]: Accept-Language from setExtraHTTPHeaders ignored in redirects with new headless mode #10235

Open mathbruyen opened 1 year ago

mathbruyen commented 1 year ago

Bug expectation

After setting Accept-Language header with setExtraHTTPHeaders, I expected the header to overridden set on all requests.

The header is sent on initial request but on redirects the header takes its default value (en-US,en;q=0.9).

Reproducer in docker: reproducer.zip

Bug behavior

Minimal, reproducible example

const http = require('node:http');
const puppeteer = require('puppeteer');

(async function () {
  const server = http.createServer((req, res) => {
    console.log(req.url, ' => ', req.headers['accept-language']);
    if (req.url === '/') {
      res.writeHead(302, {
        'location': '/redirected',
      });
    }
    res.end();
  });
  try {
    server.listen(8000);

    const oldHeadless = await puppeteer.launch({
      headless: 'old',
      args: [
        '--no-sandbox',
      ],
    });
    try {
      const oldHeadlessContext = await oldHeadless.createIncognitoBrowserContext();
      const oldPage = await oldHeadlessContext.newPage();
      await oldPage.setExtraHTTPHeaders({'Accept-Language': 'fr'});
      console.log('old mode');
      await oldPage.goto(`http://localhost:8000/`);
    } finally {
      await oldHeadless.close();
    }

    const newHeadless = await puppeteer.launch({
      headless: 'new',
      args: [
        '--no-sandbox',
      ],
    });
    try {
      const newHeadlessContext = await newHeadless.createIncognitoBrowserContext();
      const newPage = await newHeadlessContext.newPage();
      await newPage.setExtraHTTPHeaders({'Accept-Language': 'fr'});
      console.log('new mode');
      await newPage.goto(`http://localhost:8000/`);
    } finally {
      await newHeadless.close();
    }
  } finally {
    server.close();
  }
})();

Error string

Print "/redirected => fr" for both old/new headless mode

Puppeteer configuration

No response

Puppeteer version

20.3.0

Node version

20.2.0

Package manager

npm

Package manager version

9.6.6

Operating system

Linux

github-actions[bot] commented 1 year ago

This issue was not reproducible. Please check that your example runs locally and the following:

Once the above checks are satisfied, please edit your issue with the changes and we will try to reproduce the bug again.


Analyzer run

OrKoN commented 1 year ago

The new headless behaviour matches the headful behaviour so the issue is not headless mode specific.

OrKoN commented 1 year ago

Upstream https://crbug.com/1448205