How does referer work in page.goto()?

Hi there,
I am trying to add header with xk6-browser, refer to the doc Page | Playwright
the param “referer” use the string format. but with "page.setExtraHTTPHeaders(headers);
" it needs to pass an object as the param.
So I am trying to pass the header as an object, but it seems not work

Here’s my code, does anyone know which step I did incorrectly?

export function test() {

  const param = {
    headers: {
      'Content-Type': 'application/json',
      origin: env.domain,
    cookies: {
      // cookies here

  const browser = chromium.launch({ headless: false });
  const page = browser.newPage();

    .goto('', { waitUntil: 'networkidle', referer: param })
    .then(() => {
     // do something

Hi @JeffChen,

For making JSON API requests, I suggest you to use the http API instead. Let me know if that answers your question.


Hi @inanc,
for my scenario, I just want to go to my test page with some given cookies, so that I can pass the authorization part.
If I only use http request, then I can not interact with UI, right?

I tried browser.newPage({ extraHTTPHeaders: param });
It also not work

Hi @JeffChen,

Can you send us a script and an HTML page to reproduce the issue. You can use our testing site for the HTTP requests. This will allow us to come up with a solution faster.