ScreenshotNeo

BlogHow-to

How to Take a Puppeteer Screenshot of a Page with a Self-Signed Certificate

Set Puppeteer’s `acceptInsecureCerts: true` at launch, navigate to the HTTPS page, and save a screenshot. Here’s the complete workflow and troubleshooting guide.

By the ScreenshotNeo team4 October 20266 min read

To take a Puppeteer screenshot of an HTTPS page with a self-signed certificate, set acceptInsecureCerts: true in the options passed to puppeteer.launch(). Then navigate to the page, await page.screenshot(), and close the browser in a finally block. This setting lets that automation browser session continue despite certificate errors; it does not make the certificate trusted by other clients. See the Puppeteer ConnectOptions documentation and LaunchOptions documentation.

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({
    acceptInsecureCerts: true,
  });

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

Replace https://your-self-signed-host.example with the target HTTPS URL. The example saves a full-page PNG as page.png. Puppeteer documents Page.screenshot() as the capture method and supports saving to a path or returning screenshot data; use the output form that fits your application. See the Puppeteer screenshot guide and Page.screenshot() API.

What acceptInsecureCerts changes

acceptInsecureCerts tells the browser automation session to ignore HTTPS certificate errors during navigation. Its documented default is false, so a self-signed certificate can otherwise stop navigation. LaunchOptions inherits this option through ConnectOptions, which is why it belongs in the object passed to puppeteer.launch().

This is an automation setting, not a certificate repair. Keep it scoped to the browser session and target environment that needs it. If you control the development environment, configuring a locally trusted development certificate is a better long-term setup.

Step-by-step workflow

  1. Install and use Puppeteer in your project. Run the script with the Puppeteer version your project has installed, and check its documentation and typings if the option is not recognized.
  2. Launch with certificate errors accepted. Pass acceptInsecureCerts: true to puppeteer.launch(). It must apply to the browser session that owns the page.
  3. Create a page and navigate. Call browser.newPage(), then page.goto() with the HTTPS URL. Choose a wait condition that matches the page; networkidle2 is shown in Puppeteer’s screenshot example.
  4. Capture and await the result. Call await page.screenshot(...). Waiting for the promise matters: closing the browser before it completes can interrupt output.
  5. Always close the browser. Put cleanup in finally so navigation and screenshot errors do not leave the browser process running.

Choose navigation and screenshot options

The certificate setting addresses navigation through a certificate error. The remaining choices determine when the page is captured and what the output contains.

Choice When to use it Consideration
waitUntil: 'networkidle2' When the page should settle before capture; used in the official guide’s example. Pages with persistent network activity may not reach an idle state promptly. Choose a wait condition appropriate to the page.
fullPage: true When the output should include the full scrollable page. For a viewport-only capture, omit it or set it to false.
path: 'page.png' When the script should save the image directly to a file. Make sure the destination directory is writable.
Screenshot bytes or base64 When the image should be returned to application code instead of saved by path. Handle and store the returned data before closing the browser.

Consult the API for the supported screenshot options in your installed version. The browser must finish navigation sufficiently for the desired page state, but a generic network-idle wait is not right for every site.

Version-sensitive option name

Use acceptInsecureCerts with current Puppeteer. Older examples may use ignoreHttpsErrors; the Puppeteer 23.0.0 changelog records the breaking rename to acceptInsecureCerts on August 7, 2024. If a snippet fails type checking or the browser behaves differently, check the installed Puppeteer version and its matching documentation rather than assuming the older name still applies. See the Puppeteer changelog.

Browser compatibility

Puppeteer’s launch documentation says it works best with the Chrome for Testing browser downloaded by default and does not guarantee compatibility with arbitrary Chrome versions. If launch or navigation behavior differs when using a system-installed browser, check the installed Puppeteer and browser versions and compare with Puppeteer’s supported pairing. See PuppeteerNode.launch().

Troubleshooting

Symptom Likely cause Fix
The browser displays a certificate interstitial or navigation fails. The option is missing, misspelled, set on a different session, or unsupported by the installed version. Set acceptInsecureCerts: true in the launch options for the browser that owns the page. Check the installed Puppeteer version and current API docs.
A copied example uses ignoreHttpsErrors. The snippet uses the previous option name. For current Puppeteer, use acceptInsecureCerts; verify against the installed version’s docs.
A system Chrome behaves differently from the downloaded browser. The Chrome build may not be a supported Puppeteer pairing. Check the Puppeteer and browser versions. Puppeteer recommends its downloaded Chrome for Testing pairing for best compatibility.
The screenshot file is missing or incomplete. The destination may not be writable, the screenshot promise may not have completed, or the browser may have closed too early. Use a writable path, await page.screenshot(), and only then close the browser.
The capture shows a loading or incomplete page. The chosen navigation wait may not match how the site loads its content. Choose a wait condition suited to the page’s loading behavior, and capture only after the needed content is ready.
The page still has a certificate problem outside Puppeteer. acceptInsecureCerts does not install or validate a trusted certificate. For environments you control, configure a locally trusted development certificate. Do not treat the automation option as a production certificate fix.

Performance, reliability, and cost

The work is performed by a browser process, so each capture depends on launching or reusing a browser, loading the target page, and encoding the image. For repeated captures, manage browser and page lifetimes deliberately and always close resources when work ends or fails. The dossier provides no benchmark figures, so capture time and resource use should be measured in the deployment environment and against the target pages.

For reliability, use a compatible Puppeteer and browser pairing, choose a wait condition that reflects the page, await the screenshot output, and use finally cleanup. A self-signed certificate accepted by automation can still be expired, misconfigured, or untrusted by other clients; this setting only changes the browser automation behavior.

Self-hosted Puppeteer has no per-screenshot API price in this workflow, but it requires an environment to run and maintain the browser. Account for compute, browser updates, and operational work when estimating total cost. No cost or performance benchmarks are asserted here.

Or skip the browser setup

If you only need an image of a public HTTPS page, ScreenshotNeo provides a website screenshot API and MCP server. This does not configure trust for a self-signed certificate or bypass its error; use Puppeteer above for that environment. ScreenshotNeo’s one-call API example is:

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

See the ScreenshotNeo API documentation for request options. Before a capture, it accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and responses identify the page verdict and billing status in headers. Its MCP server gives AI agents tools for screenshots, page information, and PDF capture. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up free for 1,000 screenshots a month, with no card required.

FAQ

Does accepting the certificate error make the certificate trusted?

No. It changes how the Puppeteer browser session handles HTTPS errors during navigation. Other clients still validate the certificate normally.

Can I use this for a non-HTTPS page?

The option is relevant to HTTPS certificate errors. It does not change how HTTP pages work.

Should I leave this enabled for every target?

Enable it only for browser sessions that need to capture the affected environment. For environments you control, a locally trusted development certificate is a better long-term setup.

Where should I check if the option is rejected?

Check the installed Puppeteer version, its API documentation and typings, and whether the code uses the current name acceptInsecureCerts.