How to use Puppeteer to override user agent with emulation setUserAgentOverride instead of network interception?

Puppeteer

Solution

Use the Emulation.setUserAgentOverride command via a CDP session to override the user agent instead of relying on network interception.

// Puppeteer example using a CDP session
const client = await page.target().createCDPSession();
await client.send('Emulation.setUserAgentOverride', {
  userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36',
  acceptLanguage: 'en-US,en;q=0.9'
});