How can we help?

How do I add custom headers when using Playwright?

Currently, BrowserStack supports direct custom header injection when using Selenium.

However, Playwright does not support setting custom headers in the test case. By including the headers before navigating to the URL, they will be applied as expected.
To insert a custom header, the following code could be used within the Playwright test script:


const { expect, test } = require('@playwright/test');

test('Custom-Header', async ({ page }) => {
  const customHeaders = {
    "name": "value_1",  
    "value": "value_2"
  };

  await page.setExtraHTTPHeaders(customHeaders);

  //Your URL
  await page.goto('http://localhost:3000/');   
});

If this does not help resolve your issue, please reach out to our Support team.

Other Resources

Still can’t find what you are looking for?

We are always happy to help with any questions

Support resources Contact Us

Provide your business email to continue