Menu
Documentationbreadcrumb arrow Grafana k6breadcrumb arrow JavaScript APIbreadcrumb arrow k6/browserbreadcrumb arrow Pagebreadcrumb arrow setViewportSize(viewportSize)
Open source

setViewportSize(viewportSize)

This will update the page’s width and height.

ParameterTypeDefaultDescription
viewportSizeObjectAn object containing the additional HTTP headers. All header values must be strings.
viewportSize.widthnumberPage width in pixels.
viewportSize.heightnumberPage height in pixels.

Returns

TypeDescription
Promise<void>A Promise that fulfills when the viewport size is set.

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.setViewportSize({
    width: 640,
    height: 480,
  });
  await page.goto('https://test.k6.io/browser.php');
}