Getting a navigation error while trying to use .type

I am trying to use the locator.type in the k6 script. My script gives out the following year:

Uncaught (in promise) GoError: typing "sagar.thetennis" in "#signInName": execution context changed; most likely because of a navigation
running at (native)

My script is the following:

import http from 'k6/http'
import { check,sleep } from 'k6'
import {browser} from 'k6/experimental/browser'
//import { clickCheckboxOnk6 } from '@pages/example-page'
//import { htmlReport } from    "";

export const options = {
    scenarios: {
            executor: 'constant-vus',
            duration: '10s',
            vus: 1,
            options: {
            browser: {
                type: 'chromium',


export default async function() {

    const context = browser.newContext({bypassCSP: true});
    const page = context.newPage();
    try { 


    await page.goto("", { waitUntil: 'networkidle' })

    await Promise.all([
        page.locator("//button[@class='a-button right a-primary-btn']").click()
    await Promise.all([

    await Promise.all([

    //const userName= await page.locator("//div[@class='form-control ltr_override input ext-input text-box ext-text-box']")

   // await page.waitForURL('')
    //await page.context().storageState({ path: 'playwright/.auth-test/user.json' })

I think this happens because the browser is just navigating from one site to another when the script tries to locate the #signInName element, and this is because of the waitForNavigation() returns before the login page is loaded.

If you switch on debug logging and visible browser window (with K6_BROWSER_DEBUG=true and K6_BROWSER_HEADLESS=false environment variables) you see what is happening.

There are two navigation event occured after clicking the Sign in button . The first is within the document, and the second is when the login page loaded:

time="2023-10-17T22:50:25+02:00" level=debug msg="fmid:1 fid:E008062EC213DF955D5888CD1007AEF3 furl: url:" category="FrameManager:frameNavigatedWithinDocument" elapsed="0 ms" iteration_id=56ae78912b62b1f2 source=browser
time="2023-10-17T22:50:28+02:00" level=debug msg="fmid:1 fid:E008062EC213DF955D5888CD1007AEF3 pfid: docid:6184883629A08A64D0E6F7C8D8CAC9A2 fname: furl: initial:false pdoc:nil - fcurdoc:6184883629A08A64D0E6F7C8D8CAC9A2" category="FrameManager:frameNavigated" elapsed="0 ms" iteration_id=56ae78912b62b1f2 source=browser

So we have to wait both. This aproach works for me:

    await page.goto("", { waitUntil: 'networkidle' })
    await page.locator("//button[@class='a-button right a-primary-btn']").click();
    await page.waitForNavigation();    // waits the withinDocument navigation
    await page.waitForNavigation();    // waits the navigation to the login page