Running and managing scripts

Run scripts using Browsertime is easy. Create your script and run it like this:

browsertime myScript.mjs

And in you need to add the --multi switch (test multiple pages). myScript.mjs --multi

Multiple scripts

For multiple scripts, list them all in the command. This approach helps manage complex scripts by splitting them into multiple files. login.mjs measureStartPage.mjs logout.mjs --multi

Or you can break out code in multiple files.

Create a file to include exampleInclude.mjs

export async function example() {
  console.log('This is my example function');

Then include it test.mjs:

import { example } from './exampleInclude.mjs';
export default async function (context, commands) {

And then run it: --multi test.mjs

Add meta data to your script

You can add meta data like title and description to your script. The extra data will be visible in the HTML result page.

Setting meta data like this:

 * @param {import('browsertime').BrowsertimeContext} context
 * @param {import('browsertime').BrowsertimeCommands} commands
export default async function (context, commands) {
  commands.meta.setTitle('Test Grafana SPA');
  commands.meta.setDescription('Test the first page, click the timepicker and then choose <b>Last 30 days</b> and measure that page.');
  await commands.measure.start(
  await commands.wait.byTime(1000);
  await commands.measure.start('pageTimingMetrics30Days');
  await'Last 30 days');
  await commands.measure.stop();

Will result in:

Title and description for a script