Menu
Choose a product
Viewing: v1.7.x (latest)
Find another version
Scroll for more
Open source
screenshot([options])
Takes a screenshot of the element.
| Parameter | Type | Default | Description |
|---|---|---|---|
| options | object | null | |
| options.path | string | '' | 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.format | string | png | Specify screenshot type. Acceptable values are jpeg and png. |
| options.omitBackground | boolean | false | Hides default white background and allows capturing screenshots with transparency. Not applicable to jpeg images. |
| options.quality | number | 100 | The quality of the image, between 0-100; Only applicable to jpeg only. |
| options.timeout | number | 30000 | Maximum time in milliseconds. Pass 0 to disable the timeout. Default is overridden by the setDefaultTimeout option on
BrowserContext or
Page. |
Returns
| Type | Description |
|---|---|
Promise<ArrayBuffer | null> | The ArrayBuffer with the captured screenshot. |
Example
JavaScript
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');
const element = await page.$(".header");
const screenshot = await element.screenshot({
path: 'header.png'
});
await page.close();
}Was this page helpful?
Related resources from Grafana Labs
Additional helpful documentation, links, and articles:
Video

Performance testing and observability in Grafana Cloud
Optimize user experiences with Grafana Cloud. Learn real-time insights, performance testing with k6, and continuous validation with Synthetic Monitoring.
Events

User-centered observability: load testing, real user monitoring, and synthetics
Learn how to use load testing, synthetic monitoring, and real user monitoring (RUM) to understand end users' experience of your apps. Watch on demand.