Skip to content

k6 browser does not surface browser network errors when navigating to a page #4895

@nadiamoe

Description

@nadiamoe

Brief summary

A script that navigates and waits for a page to load will report no error even if Chromium cannot load that page due to a network error.

k6 version

k6 v1.1.0 (go1.24.4, linux/amd64)

OS

Arch linux (btw)

Docker version and image (if applicable)

N/A

Steps to reproduce the problem

Run the following script, provided that nothing is running on localhost:4444 (so connections to that port will fail):

import { browser } from 'k6/browser';

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

export default async function () {
  const context = await browser.newContext();
  const page = await context.newPage();
  const startUrl = 'http://localhost:4444';

  try {
    await page.goto(startUrl);
    await page.waitForLoadState('networkidle');
    const myLocator = await page.locator('#something');
    // myLocator.click();
  } catch (error) {
    console.error(error);
  } finally {
    await page.close();
  }
}

Expected behaviour

k6 should error out complaining that the page it was asked to navigate to was unreachable.

Actual behaviour

k6 will report somewhat sensical data and exit with success (0):

nadia@Nadiarch 󱃾 curry-admin@Curry
17:58:37 /tmp/nadia $> k6 run repro.js

         /\      Grafana   /‾‾/
    /\  /  \     |\  __   /  /
   /  \/    \    | |/ /  /   ‾‾\
  /          \   |   (  |  (‾)  |
 / __________ \  |_|\_\  \_____/


     execution: local
        script: repro.js
        output: -

     scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
              * ui: 1 iterations shared among 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)



  █ TOTAL RESULTS

    EXECUTION
    iteration_duration.............................: avg=2.13s    min=2.13s    med=2.13s    max=2.13s    p(90)=2.13s    p(95)=2.13s
    iterations.....................................: 1     0.438437/s
    vus............................................: 1     min=1      max=1
    vus_max........................................: 1     min=1      max=1

    NETWORK
    data_received..................................: 0 B   0 B/s
    data_sent......................................: 0 B   0 B/s

    BROWSER
    browser_data_sent..............................: 185 B 81 B/s

    WEB_VITALS
    browser_web_vital_cls..........................: avg=0        min=0        med=0        max=0        p(90)=0        p(95)=0
    browser_web_vital_fcp..........................: avg=36ms     min=36ms     med=36ms     max=36ms     p(90)=36ms     p(95)=36ms
    browser_web_vital_lcp..........................: avg=36ms     min=36ms     med=36ms     max=36ms     p(90)=36ms     p(95)=36ms
    browser_web_vital_ttfb.........................: avg=399.99µs min=399.99µs med=399.99µs max=399.99µs p(90)=399.99µs p(95)=399.99µs




running (00m02.3s), 0/1 VUs, 1 complete and 0 interrupted iterations
ui   ✓ [======================================] 1 VUs  00m02.3s/10m0s  1/1 shared iters

If the commented line myLocator.click(); is uncommented, then k6 will return an error:

WARN[0002] Unexpected DevTools server error: context canceled  category="ExecutionContext:eval" elapsed="0 ms" source=browser
ERRO[0002] Uncaught (in promise) clicking on "#something": getting injected script: context canceled  executor=shared-iterations scenario=ui

The fact that the error is surfaced when an action is performed misleads users to think the problem lies in that action, and not in the page not being loaded in the first place.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions