How to set user agent in Puppeteer?

To set user agent in Puppeteer, you can use the setUserAgent method available in the page object. Here's an example:

const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); // Set user agent await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'); // Navigate to a website await page.goto('https://example.com'); // Continue with your code here await browser.close(); })();

In this example, the setUserAgent method is called on the page object to set a custom user agent string before navigating to a website. You can replace the user agent string with any desired user agent.