Websocket: close 1006 (abnormal closure): unexpected EOF on navigation

Brief summary

When the testing script runs for over 30 seconds the browser closes automatically, disrupting the test.

xk6-browser version

k6 v0.42.0 ((devel), go1.19.4, linux/amd64)

OS

Ubuntu Linux 22.04.1 LTS

Chrome version

Chromium 109.0.5414.119 snap

Docker version and image (if applicable)

No response

Steps to reproduce the problem

import { sleep } from 'k6';
import { chromium } from 'k6/x/browser';

export default function () {

    const browser = chromium.launch({ headless: false });
    const page = browser.newPage();
  
    page.goto("https://k6.io/docs/javascript-api/xk6-browser/api/page/")
      .then(() => {
          sleep(30);
          console.log("After 30 seconds")
          page.goto("https://k6.io/docs/javascript-api/xk6-browser/api/page/")
          console.log("After trying to goto k6 again")
          page.close()
          browser.close()
      })
  }

Expected behaviour

The browser should remain open

Actual behaviour

The browser closes automatically failing the test

Hi @george.l! Welcome to the forum!

In regards of your question, I believe the error is because you are mishandling the promise returned by the second call to page.goto. See my example on one option to do that:

export default function () {

    const browser = chromium.launch({ headless: false });
    const page = browser.newPage();
  
    page
    .goto('https://k6.io/docs/javascript-api/xk6-browser/api/page/', { waitUntil: 'networkidle' })
    .then(() => {
        sleep(5);
        console.log("After 5 seconds");
        return page.goto("https://k6.io/docs/javascript-api/xk6-browser/api/browser/", { waitUntil: 'networkidle' });
    })
    .then(() => {
        console.log("After trying to goto k6 again");
    })
    .finally(() => {
      page.close();
      browser.close();
    });
}

Another option is to use the latest released version of xk6-browser (v0.8.0) which has support for async / await API and the promises handling can be simplified. See an example:

export default async function () {

    const browser = chromium.launch({ headless: false });
    const page = browser.newPage();
  
    await page.goto('https://k6.io/docs/javascript-api/xk6-browser/api/page/', { waitUntil: 'networkidle' });
    sleep(5);
    console.log("After 5 seconds");
    await page.goto("https://k6.io/docs/javascript-api/xk6-browser/api/browser/", { waitUntil: 'networkidle' });
    console.log("After trying to goto k6 again");
    page.close();
    browser.close();
}

Let me know if that helps.
Regards.

1 Like

Hey Daniel and thank you!
The issue persists in the first example you sent me if you change the sleep(5) to sleep(30). The browser seems to be closing after 30 seconds no matter the testing script!

Hi @george.l ,

I believe that is because by default chromium browser defines a default 30s timeout. See launch options. You can change that initializing the browser like:

const browser = chromium.launch({
        timeout: '1m', // Or whatever time you want to define
        headless: false
    });

Let me know if that fixes the issue.

1 Like

That did the trick. Thank you Daniel!

1 Like