Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk5 min

How to Use Browserless Screenshots with Puppeteer

Connect Puppeteer to Browserless’s remote Chromium, capture a page, and choose between a stateful browser session and a one-shot REST screenshot.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use puppeteer-core to connect Puppeteer to Browserless’s hosted Chromium, navigate to a page, and save the result with page.screenshot(). You need a Browserless API token and the WebSocket endpoint for your region. Close the browser connection in a finally block so the remote session does not linger.

Connect Puppeteer to Browserless

Because Browserless runs Chromium remotely, install puppeteer-core rather than the full puppeteer package. The full package downloads a local Chromium binary during installation, which this workflow does not need. Browserless’s current walkthrough uses puppeteer-core and puppeteer.connect() to attach to its hosted browser (Browserless Puppeteer connection guide).

As an Amazon Associate I earn from qualifying purchases.

  1. Install the package with npm install puppeteer-core.
  2. Get an API token from your Browserless account dashboard.
  3. Set the token in an environment variable named BROWSERLESS_TOKEN; do not commit it to source control.
  4. Use the WebSocket endpoint for your Browserless deployment and region. The SFO production hostname below is the endpoint shown in the official example, not a universal hostname.

Save this as screenshot.mjs and run it with Node.js:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import puppeteer from 'puppeteer-core';

const TOKEN = process.env.BROWSERLESS_TOKEN;
if (!TOKEN) throw new Error('Set BROWSERLESS_TOKEN before running this script.');

const browser = await puppeteer.connect({
  browserWSEndpoint: `wss://production-sfo.browserless.io?token=${TOKEN}`,
});

try {
  const page = await browser.newPage();
  await page.goto('https://example.com/', { waitUntil: 'networkidle2' });
  await page.screenshot({ path: 'screenshot.png', fullPage: true });
} finally {
  await browser.close();
}

For example, on a POSIX shell, run BROWSERLESS_TOKEN=your_token node screenshot.mjs. On other shells, set the environment variable using that shell’s syntax before running the script. The token-in-query-string pattern and page workflow follow Browserless’s documented connection approach (connection guide; screenshot walkthrough).

Why the cleanup matters

browser.close() ends the remote session. If the script exits without closing the connection, the session can remain active until timeout and may incur billed session time, according to Browserless’s connection guide (Browserless connection guide). Keeping the cleanup in finally ensures it runs even if navigation or capture throws an error.

Choose Puppeteer or Browserless’s REST screenshot endpoint

Workflow Use it when How it handles the capture
Puppeteer WebSocket connection You need page interaction, selectors, custom waits, or several operations in one browser session. Connect to the remote browser, control the page with Puppeteer, and save the screenshot with page.screenshot().
Browserless /screenshot REST endpoint You need one screenshot without custom interaction or a continuing browser session. Send a POST request with a URL or raw HTML, an API token, and screenshot options; save the returned image bytes.

Browserless describes the WebSocket approach as connecting existing Puppeteer code to a managed browser. Since the remote browser starts before your script connects, startup options belong in the connection URL; array-valued Chrome arguments use the encoded launch parameter (connection guide; launch options). For a one-shot REST capture, Browserless documents the /screenshot endpoint and returns image bytes (screenshot endpoint; REST API guide).

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Configure the screenshot and wait for the page

With Puppeteer, common page.screenshot() options include path, fullPage, type, quality, and clip. Use fullPage: true for content beyond the current viewport. Quality is relevant to lossy formats such as JPEG or WebP, not PNG. Browserless’s REST screenshot options support PNG, JPEG, WebP, full-page capture, quality, clip regions, viewport-related settings, and selector-based capture (Browserless screenshot API; screenshot option reference).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Wait for content that loads late

The example uses waitUntil: 'networkidle2' for navigation, but a page’s network activity is not always a reliable signal that every visual element is ready. If the page renders a specific component after navigation, wait for that selector before capturing:

await page.goto('https://example.com/', { waitUntil: 'domcontentloaded' });
await page.waitForSelector('.report-ready', { timeout: 15000 });
await page.screenshot({ path: 'report.png', fullPage: true });

Replace .report-ready with a selector that appears only when the desired content is present. For pages that load images or other content on scroll, scroll through the page before capturing; Browserless’s REST API also offers a scrollPage request setting to trigger lazy-loaded content. Pair scrolling with full-page capture when the page is long (screenshot API; screenshot walkthrough).

Use REST options for a one-shot PNG

A REST request puts capture settings in an options object. This example shows the request body shape for a full-page PNG; follow Browserless’s current authentication instructions for the token when sending the POST request.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
{
  "url": "https://example.com/",
  "options": {
    "fullPage": true,
    "type": "png"
  }
}

Use this route when a single request is enough and you do not need to run page interactions between navigation and capture (screenshot endpoint; REST API guide).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Troubleshoot incomplete or failed captures

  • Connection fails: Check that BROWSERLESS_TOKEN is set and valid, and that the WebSocket hostname matches the endpoint for your deployment and region. Do not assume the SFO example endpoint applies to every account.
  • The job finishes but no screenshot file appears: Confirm the output path is writable and that the script reached page.screenshot(). Inspect navigation and capture errors rather than swallowing exceptions.
  • The screenshot misses late content: Wait for a page-specific selector or suitable condition before capture. For lazy-loaded sections, scroll to trigger loading, then take a full-page screenshot.
  • The image is blank, shows a CAPTCHA, or says access denied: Browserless identifies bot detection as a likely reason. Its separate /unblock endpoint can handle some anti-bot cases and can return a screenshot when configured to do so, but it is not a guarantee for every protected site (screenshot documentation; unblock endpoint).
  • Remote sessions appear to remain active: Ensure browser.close() runs in a finally block; an unclosed connection may remain active until timeout and may incur billed session time (connection guide).
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use ScreenshotNeo when you do not need a remote Puppeteer session

If you only need a screenshot from a URL and do not need Browserless-hosted Chromium or page-level Puppeteer interaction, ScreenshotNeo offers a one-request screenshot API. Its clean-capture steps can accept cookie and consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets; those steps can be turned off. Bot checks and failed captures are not billed, and an MCP server provides screenshot tools for AI agents. See the ScreenshotNeo API documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com/ -o shot.webp

ScreenshotNeo returns an image or PDF from one GET request; its pricing includes 1,000 shots per month on the free plan with no card, and paid plans start at $5 for 3,000 shots. Sign up free for 1,000 screenshots a month with no card.

Frequently Asked Questions

Does Browserless run the browser on my machine?

No. In this workflow Browserless hosts Chromium and Puppeteer connects to it remotely over a WebSocket.

Can I use the full Puppeteer package instead of puppeteer-core?

You can, but the full package downloads a local Chromium binary during installation; puppeteer-core avoids that unnecessary download for a remote-browser connection.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.