Setting Language in Puppeteer in Mac OSX Not Working

Viewed 246

It seems that setting the language for chromium in Mac OSX is not working. I've seen other questions that seem to solve the issue generally, but it's not working for me at least in Mac OSX and I've seen some comments that others cannot get this working in MacOS.

  const browser = await puppeteer.launch({
    headless: true,
    args: ['--lang="en-US"'],
  });

I am in Israel and my results are in Hebrew. If I evaluate the page and do navigator.language I get "en-US" which seems right. If I open the browser headful and examine the lang attr of the html element I see "IW".

If I launch the same version of Chromium that Puppeteer is using:

$ node_modules/puppeteer/.local-chromium/mac-756035/chrome-mac/Chromium.app/Contents/MacOS/Chromium  --lang="en-US"

my results are in English.

I've also tried this:

await page.setExtraHTTPHeaders({
    'Accept-Language': 'en'
});

and

await page.evaluateOnNewDocument(() => {
    Object.defineProperty(navigator, "language", {
        get: function() {
            return ["en-US"];
        }
    });
    Object.defineProperty(navigator, "languages", {
        get: function() {
            return ["en-US", "en"];
        }
    });
});

to no avail.

0 Answers
Related