Skip to main content

Screenshots

The screenshot mutation navigates to a URL and captures a screenshot. Browserless returns the image as a base64-encoded png, jpg, or webp.

Basic Usage

Navigate to a URL and capture the page. Wait for elements to load before capturing to avoid blank or incomplete screenshots.

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

screenshot(omitBackground:true) {
base64
}
}

Setting HTML Content

The content mutation sets the page HTML directly, without navigating to a URL. Use it to screenshot dynamically generated markup.

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

screenshot(type: webp) {
base64
}
}

Element-specific Screenshots

The selector parameter captures a specific element instead of the full page. Use it to focus on a component, widget, or section.

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

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

Transparent Background Screenshots

Set omitBackground: true to capture a transparent background instead of the default white. Requires type: png. JPEG does not support transparency.

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

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

Clipped Region Screenshots

The clip parameter captures a rectangular region defined by pixel coordinates. Use it when the target area does not correspond to a single CSS selector.

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

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

Next Steps