Guide

Screenshots and PDFs

A picture of the page or of one element. A PDF straight to a file. Which providers do it without a session

Screenshot

shell
browsers screenshot https://example.com -o page.png -p playwright
text
[provider=playwright] Screenshot of https://example.com: image/png, 73785 bytes, saved to /home/you/page.png.

Screenshots capture the full page by default. Use --no-full-page for the viewport and -f for png, jpeg or webp. Without -o, stdout gets only the summary. Stderr notes that the image block wasn't printed. With -o, an existing file is an error.

In TypeScript it's provider.screenshot({ url, fullPage, format, selector, waitFor, viewport }), and the result carries the image as base64 in data plus its mimeType. A provider with statelessScreenshot false wants a session for that, same deal as Kernel and scrape. The CLI and the tools open one for you.

One element

shell
browsers screenshot https://httpbin.org/forms/post -o form.png --selector form

--selector captures the first element that matches, not the page. Cloudflare, Browserless and Playwright can do it, the flag is elementScreenshot. Leave the provider out and the first configured one of those gets the job. Attach can too, but only by name. Name another one and it refuses. It won't quietly hand you the whole page and pretend.

A selector that matches nothing is the vendor's error, passed through. Browserless says Element not found on page!, which is at least honest.

Wait for it

shell
browsers screenshot https://quotes.toscrape.com/js-delayed/ -o quotes.png -p playwright --no-full-page --wait-for .quote
text
[provider=playwright] Screenshot of https://quotes.toscrape.com/js-delayed/: image/png, 77328 bytes, saved to /home/you/quotes.png.

A screenshot fires the moment the page loads. Fine for a static page. That one paints its quotes a few seconds later, though. Without --wait-for you get a lovely picture of an empty list and a Next → button. With it the shot waits for .quote, same as scrape's --wait-for.

Who can wait? Cloudflare, Browserless and Playwright, the flag is screenshotWaitFor. Provider choice works like --selector: leave it out and one of those three gets the job. Attach waits too, by name. Name Steel, Anchor, Kernel or Hyperbrowser and you get a refusal. Beats a confident shot of the wrong state:

text
steel cannot wait for a selector before a screenshot. Use cloudflare, browserless or playwright, or drop waitFor.

On Playwright and Browserless a selector that never shows up gets 25 seconds. Then you hear its name. Playwright says waitFor ".nope" didn't show up within 25s. Browserless answers 408 with waiting for DOM selector ".nope". The client retries a 408, so that verdict takes its time.

For a model

browsers_screenshot returns the image itself, so a model that reads images sees the page. A capture whose base64 runs past 5 MB can't go back inline, so pass path and it writes a file instead. path never overwrites. An existing file is an error, not a surprise.

selector and fullPage: true together are an InvalidInputError. Pick one.

PDF

shell
browsers pdf https://example.com -o page.pdf -p playwright
text
[provider=playwright] PDF of https://example.com: 36237 bytes, saved to /home/you/page.pdf.

Cloudflare, Browserless and Playwright print PDFs. The CLI requires -o. browsers_pdf writes to path, and an existing file is an error. For landscape pages, use the library: provider.pdf(url, { landscape: true }).