Menu

Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.

Open source

screenshot([options])

Returns the buffer with the captured screenshot from the browser.

ParameterTypeDefaultDescription
optionsobjectnull
options.clipobjectnullAn object which specifies clipping of the resulting image.
options.clip.xnumber0x-coordinate of top-left corner of clip area.
options.clip.ynumber0y-coordinate of top-left corner of clip area.
options.clip.widthnumber0Width of clipping area.
options.clip.heightnumber0Height of clipping area.
options.fullPagebooleanfalseWhen true, takes a screenshot of the full scrollable page, instead of the currently visible viewport.
options.omitBackgroundbooleanfalseHides default white background and allows capturing screenshots with transparency. Not applicable to jpeg images.
options.pathstring''The file path to save the image to. The screenshot type will be inferred from file extension. If path is a relative path, then it is resolved relative to the current working directory. If no path is provided, the image won’t be saved to the disk.
options.qualitynumber0The quality of the image, between 0-100; Only applicable to jpeg only.
options.typestringpngSpecify screenshot type. Acceptable values are jpeg and png.

Returns

TypeDescription
BufferThe buffer with the captured screenshot.

Example

JavaScript
import { browser } from 'k6/experimental/browser';

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

export default async function () {
  const page = browser.newPage();

  await page.goto('https://test.k6.io/browser.php');
  page.screenshot({ path: 'screenshots/browser.png' });
}