No results for

Powered byAlgolia
⚠️ This is the archived documentation for k6 v0.47. Go to the latest version.

on(event, handler)

Registers a handler to be called whenever the specified event occurs.

eventstring''Event to attach the handler to. Currently, only the 'console' event is supported.
handlerfunctionnullA function to be called every time the specified event is emitted.

When using the page.on method, the page has to be explicitly closed for the iteration to be able to finish.


consoleEmitted every time the console API methods are called from within the page JavaScript context. The arguments passed into the handler are defined by the ConsoleMessage class.


import { browser } from 'k6/x/browser';
import { check } from 'k6';
export const options = {
scenarios: {
ui: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
thresholds: {
checks: ["rate==1.0"]
export default async function() {
const page = browser.newPage();
try {
await page.goto('');
page.on('console', msg => {
check(msg, {
'assertConsoleMessageType': msg => msg.type() == 'log',
'assertConsoleMessageText': msg => msg.text() == 'this is a console.log message 42',
'assertConsoleMessageArgs0': msg => msg.args()[0].jsonValue() == 'this is a console.log message',
'assertConsoleMessageArgs1': msg => msg.args()[1].jsonValue() == 42,
page.evaluate(() => console.log('this is a console.log message', 42));
} finally {
page.close(); // required so iteration can end