Skip to main content

Screenshots

The screenshot mutation allows for simple navigation to a site and capturing a screenshot. Browserless will respond with either a binary or base64 encode of a png or jpg (depending on parameters).

On this collection we'll look at:

BQL Schemas

For more details on BQL mutations, refer to the BrowserQL Schema reference pages.

Rest API

Taking Screenshots can also be done with Browserless Rest API. For endpoint details, parameters, and code samples, see the Browserless REST API.

Basic Usage

mutation Screenshot {
goto(url: "https://example.com") {
status
}

screenshot(omitBackground:true) {
base64
}
}
Waiting for Elements

For more reliable screenshots, it's important to wait for the site and elements to be ready before capturing. Learn more about BrowserQL's built-in wait methods in our Waiting for Things documentation.

Setting HTML Content

You can set the HTML content of the page to render dynamically generated content.

mutation Screenshot {
content(html: "<h1>Hello, World!</h1>") {
status
}

screenshot(type: webp) {
base64
}
}

Element-specific Screenshots

Use the selector parameter to capture screenshots of specific page elements instead of the entire page. This is useful for focusing on particular components, widgets, or sections of a webpage.

mutation ElementScreenshot {
goto(url: "https://example.com") {
status
}

screenshot(selector: "h1") {
base64
}
}

Transparent Background Screenshots

Use omitBackground: true to capture screenshots with transparent backgrounds instead of the default white background. This is particularly useful when creating overlays or when you need to composite the screenshot with other images.

mutation TransparentScreenshot {
goto(url: "https://example.com") {
status
}

screenshot(omitBackground: true, type: png) {
base64
}
}
PNG Required

Transparent backgrounds only work with PNG format. Make sure to set type: png when using omitBackground: true.

Clipped Region Screenshots

Use the clip parameter to capture a precise rectangular region of the page by specifying exact pixel coordinates. This is useful when you need to capture a specific area that doesn't correspond to a CSS selector.

mutation ClippedScreenshot {
goto(url: "https://example.com") {
status
}

screenshot(clip: { x: 100, y: 200, width: 800, height: 600 }) {
base64
}
}

Next Steps

Ready to take your screenshot automation to the next level? Explore these key areas: