Menu

This is documentation for the next version of K6. For the latest stable release, go to the latest 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
Promise<Buffer>A Promise that fulfills with the Buffer with the captured screenshot.

Example

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

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

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

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