How to add custom headers to a request in Puppeteer?

To add custom headers to a request in Puppeteer, you can use the page.setExtraHTTPHeaders method. Here is an example of how you can add custom headers to a request:

const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.setExtraHTTPHeaders({ 'Custom-Header-1': 'Value1', 'Custom-Header-2': 'Value2' }); await page.goto('https://example.com'); // Other actions on the page await browser.close(); })();

In this example, we use the setExtraHTTPHeaders method to set custom headers for all requests made by the page. You can specify any custom headers you want to add as key-value pairs in the object passed to the method. These headers will be included in all requests made by the page during its navigation.