Search code examples
node.jspuppeteerheadless-browsergoogle-chrome-headlessserver-side-rendering

Change locale on the fly after browser initialization with puppeteer


With puppeteer, can we change the lang after we specified it during the browser launching ?

In my code below, I'm specifying the lang with the --lang parameter for chrome headless but I would love to know if later in my code we can change, on the fly, the language...

Here's how I set the lang in a first time :

const browser = await puppeteer.launch({
    args: [`--lang=${lang}`]
});

... some stuff here
// then change the lang here

Then after in my code I've been tried to change like that (but it's doesn't work) :

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

I found this solution here : How to specify browser language in Puppeteer

Also I have tried to create a wsEndpoint (it's what I want to do in fact, like the Ebidel's article : https://developers.google.com/web/tools/puppeteer/articles/ssr#reuseinstance) and to change the lang like that :

const browser = await puppeteer.connect({
   browserWSEndpoint,
   args: [`--lang=${lang}`]
});

...but it's still doesn't work.

Have you an idea how to do that ? I've found few topics about that.


Solution

  • Finally there's no way to do that for the moment.