What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

Protocol error (Page.captureScreenshot): Target closed means Puppeteer tried to capture a page whose Chrome DevTools Protocol target no longer existed. The page may have been closed by your code, its browser connection may have ended, or Chromium may have crashed. Find out which happened before changing screenshot options: the message describes a lost target, not a single universal cause.

What “Target closed” means during a screenshot

Puppeteer sends commands to Chromium over the Chrome DevTools Protocol (CDP). A page is represented by a target. If that target disappears while Puppeteer is sending or awaiting Page.captureScreenshot, Puppeteer cannot complete the command and reports a target-closed error. Puppeteer issue #1385 records the screenshot-specific message, Error: Protocol error (Page.captureScreenshot): Target closed.

The error is therefore a lifecycle symptom. It does not, by itself, tell you whether an application closed the page too soon or Chromium lost the target because the process or connection failed. The timing and surrounding logs matter:

  • During or immediately after page.screenshot(): check whether page or browser cleanup ran while the screenshot was still pending.
  • After a Promise.race or other concurrent work: check for unfinished operations that continue using the page after another promise wins.
  • At launch or intermittently in a container: investigate Chromium startup, crashes, runtime libraries and image compatibility as well as JavaScript cleanup.

First fix: await the screenshot before closing anything

Every page operation that must finish should be awaited, and page cleanup should come afterward. This basic sequence makes the intended lifetime explicit:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
await page.goto(url, {waitUntil: 'networkidle2'});
await page.screenshot({path: 'shot.png', fullPage: true});
await page.close();

If the screenshot promise is not awaited, execution can reach page.close() or browser.close() while Chromium is still capturing. Puppeteer issue #1385 illustrates an unresolved screenshot promise failing with the target-closed error. Adding a delay is not a substitute for correct sequencing: it does not establish that the operation has completed.

For a script that owns the browser and page, use try/finally so cleanup still happens if navigation or capture throws:

const puppeteer = require('puppeteer');

async function capture(url) {
  const browser = await puppeteer.launch();
  try {
    const page = await browser.newPage();
    try {
      await page.goto(url, {waitUntil: 'networkidle2'});
      await page.screenshot({path: 'shot.png', fullPage: true});
    } finally {
      if (!page.isClosed()) {
        await page.close();
      }
    }
  } finally {
    await browser.close();
  }
}

capture('https://example.com').catch(error => {
  console.error(error);
  process.exitCode = 1;
});

This is a safe ordering pattern, not a guarantee against Chromium crashes or environment problems. In a larger application, adapt cleanup to ownership: a function that receives a shared page should generally not close it unless that responsibility is part of its contract.

Trace every path that can close the page or browser

Search the code path—not just the screenshot function—for calls to page.close(), browser.close(), browser-context close methods, timeout callbacks and error handlers. A cleanup handler can run concurrently with capture, especially when navigation, request handling and screenshot work are coordinated by separate promises.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors

Log each lifecycle event with a timestamp and a page or job identifier. At minimum, record entry into and completion of navigation, evaluation and screenshot calls; every page or context close; browser shutdown; and process exit. Also listen for browser disconnection and page closure or crash events. For example:

browser.on('disconnected', () => {
  console.error('Browser disconnected');
});

page.on('close', () => {
  console.error('Page closed');
});

page.on('error', error => {
  console.error('Page crashed:', error);
});

Use the event names supported by the Puppeteer version in your project. The aim is to establish whether your own cleanup ran first or whether the browser vanished unexpectedly. If a timeout handler closes the page, log the timeout reason and whether capture was still in progress; otherwise a timeout can look like an unexplained screenshot failure.

Handle Promise.race and concurrent waits without orphaning work

Promise.race() settles when the first input promise settles. It does not automatically cancel the other promises. A losing wait can therefore continue to access the page after your code believes the race is finished and begins cleanup.

Puppeteer issue #6610 discusses this pattern: a maintainer recommends awaiting the operation, and the follow-up points out that race losers must also finish before the page is closed. Keep references to all page-related promises. After the winner is known, either cancel remaining work using a cancellation mechanism that the operation actually supports, or wait for it to settle before closing the page. Do not assume that abandoning a promise cancels its CDP command.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.

For example, this sketch shows the sequencing principle; it is not a general cancellation API:

const navigation = page.goto(url, {waitUntil: 'networkidle2'});
const deadline = new Promise((_, reject) => {
  setTimeout(() => reject(new Error('Navigation deadline exceeded')), 30000);
});

try {
  await Promise.race([navigation, deadline]);
  await page.screenshot({path: 'shot.png'});
} finally {
  // Do not close the page while page work is still pending.
  await navigation.catch(() => {});
  if (!page.isClosed()) await page.close();
}

In production, also clear timers when they are no longer needed and ensure your timeout strategy cannot leave a long-running operation hanging indefinitely. If the underlying operation cannot be safely cancelled or settled, treat the page as still in use; design the owner of the page to decide how to recover rather than closing it from a competing callback.

Wait for evaluation and exposed-function work to finish

page.evaluate() and functions exposed to page code can initiate asynchronous work. If cleanup follows before that work completes, callbacks or evaluation results may still depend on a target that has already been closed. Await the evaluation promise and any application-level work it starts before closing the page.

Puppeteer issue #1385 concerns an earlier screenshot failure; a separate report concerns evaluation cleanup.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient

Issue #1385 records the screenshot protocol message. The separate report identified in the Puppeteer issue tracker links close ordering to a target-closed failure, and notes that adding delays did not resolve the close/reopen behavior. Do not use arbitrary sleeps as a lifecycle fix; determine which evaluation, callback or exposed-function work is still outstanding and await or clean it up deliberately.

When the browser process or container may be the cause

If the failure happens during launch, appears intermittently without an obvious close call, or affects a containerized deployment, investigate Chromium itself. A CDP error can be the visible consequence of a browser that failed to start or exited unexpectedly.

Capture Chromium stderr and its exit status

Preserve browser stderr and the Chromium process exit code alongside the Puppeteer stack trace. Look for a preceding startup or crash message. In Puppeteer issue #6258, a missing shared library—libgobject-2.0.so.0—produced an underlying error reading “error while loading shared libraries” and surfaced as a target-closed protocol message during launch. Installing the required runtime dependency for the chosen image, or using a compatible image, addresses that kind of failure; changing screenshot timing does not.

Check the full runtime combination in Docker

Record the Node.js version, Puppeteer version, Chromium version, operating system and base-image version. Compare those details when the failure occurs only in one deployment or after an image change. Puppeteer issue #10153 documents intermittent Target.setAutoAttach: Target closed failures in a Docker/Alpine environment. While isolating a similar problem, remove experimental launch flags and change one environment variable at a time so you can identify what affects the result.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

Do not infer that every Alpine or Docker installation is broken from an issue report. The useful diagnostic is whether the browser process, dependencies and versions in your particular image are compatible and whether stderr shows a crash or startup failure.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Diagnose the failure by when it occurs

When the error appears What to inspect first Next action
At page.screenshot(), after a close call Whether screenshot and earlier page operations were awaited; concurrent cleanup paths Sequence capture before page/context/browser close, then log each close path.
After a race, timeout or evaluation Unsettled race losers, outstanding evaluation, callbacks or exposed-function work Retain promise references; settle or cancel supported work before cleanup.
During launch or with a browser exit Chromium stderr, process exit status and missing shared libraries Fix the runtime dependency or use a compatible runtime image.
Intermittently in Docker/Alpine Node, Puppeteer, Chromium and base-image versions; experimental launch flags Capture exact versions, remove experimental flags while isolating, and test a compatible combination.

Record versions before comparing fixes

Include exact Puppeteer, Node.js, Chromium and OS/container versions in bug reports and deployment logs. Error classes and target/session behavior have changed across Puppeteer releases; the changelog is a reminder that old stack traces and suggested fixes may not map exactly to a current version. Compare reports only after matching the relevant runtime details, and consult the changelog for the release you are using.

Troubleshooting checklist

  • Is page.screenshot() explicitly awaited, along with every page operation before it?
  • Can any timeout, error handler or parallel task close the page, context or browser first?
  • Does a Promise.race leave a losing page operation active?
  • Does evaluation or exposed-function work continue after the code starts cleanup?
  • Do browser stderr or the process exit status show a launch failure or crash?
  • Are the Node, Puppeteer, Chromium and container versions recorded and compatible in the environment where the error occurs?

Or skip the browser setup

If you need a screenshot rather than control over a local Puppeteer browser lifecycle, ScreenshotNeo provides a screenshot API and MCP server. Its one-call API can return an image or PDF; use this cURL example to save a WebP screenshot. See the ScreenshotNeo API documentation for request parameters and output options.

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

ScreenshotNeo accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups and chat widgets before capture; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads and cache hits cost nothing, and response headers report the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info and capture_pdf for Claude, Cursor and other MCP clients. The Free plan includes 1,000 screenshots 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.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

FAQ

Does “Target closed” always mean Puppeteer closed the page?

No. An application close is one possibility, but a browser disconnect or Chromium crash can also make the target unavailable. Use close-event logs and browser stderr to distinguish them.

Will upgrading Puppeteer necessarily fix the error?

Not necessarily. Versions matter when interpreting target/session errors, but an upgrade will not correct a page closed by your own cleanup or install a missing system library. Diagnose the lifecycle and runtime evidence first.

Frequently Asked Questions

Does “Target closed” always mean Puppeteer closed the page?

No. An application close is one possibility, but a browser disconnect or Chromium crash can also make the target unavailable. Use close-event logs and browser stderr to distinguish them.

Will upgrading Puppeteer necessarily fix the error?

Not necessarily. Versions matter when interpreting target/session errors, but an upgrade will not correct a page closed by your own cleanup or install a missing system library. Diagnose the lifecycle and runtime evidence first.

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.