Browser mode does not work

I am using the latest version 0.57. I aim to use K6 browser mode but the browser does not open. I am adding console logs and see that the URL is constantly null. I am using the script from K6’s website, but the browser mode does not work.

import { browser } from 'k6/browser';

export const options = {
  scenarios: {
    ui: {
      executor: 'shared-iterations',
      options: {
        browser: {
          type: 'chromium',
        },
      },
    },
  },
};

export default async function () {
  const page = await browser.newPage();

  try {
    await page.goto('https://test.k6.io/');
	console.log(page.url);
  } finally {
    await page.close();
  }
}


K6_BROWSER_DEBUG=true k6 run k6BrowserDemoExample.js
'K6_BROWSER_DEBUG' is not recognized as an internal or external command,
operable program or batch file.
K6_BROWSER_HEADLESS=false k6 run k6BrowserDemoExample.js
'K6_BROWSER_HEADLESS' is not recognized as an internal or external command,
operable program or batch file.

I can’t see any information that the K6 browser mode is working. My tests are failing because the web page I want to open is not opening. I see in the logs that the URL is null. I couldn’t get a result despite trying many different methods. I couldn’t get the browser to open in any way.

Hi @cataseven1

Welcome to the community forums! :wave:

What OS do you use?

I solved the browser opening issue with the following command

 set "K6_BROWSER_HEADLESS=false" && k6 run k6BrowserDemoExample.js

I found out that the reason why the URL was returning null was that I was using the wrong script for the console log. The correct script is as follows.

console.log(await page.url());