October 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 NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

Puppeteer Screenshot Memory Leaks: Close Pages and Browsers Correctly

Await screenshots, then close the page, context or browser your job owns. Learn the correct cleanup patterns and how to dispose ElementHandles.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

After capturing a screenshot, await page.screenshot() and close the resource your job owns: the page, its BrowserContext, or the whole browser. Use try/finally so cleanup also runs when navigation or capture fails. browser.disconnect() is not a substitute for closing a browser you own—it leaves the browser and its pages running.

Close the right Puppeteer resource

Choose the cleanup boundary based on how the browser is used. A one-off script can close the browser; a shared, long-lived browser should normally close only the resources belonging to the finished job.

As an Amazon Associate I earn from qualifying purchases.

Resource What closing it does When to use it
page.close() Closes that page. It returns a promise, so await it. The browser stays open for other work, and the page is no longer needed. Puppeteer Page.close() API
context.close() Closes the BrowserContext and all pages associated with it. The default BrowserContext cannot be closed. A task owns an isolated context and its pages; close the context when that task ends. Puppeteer browser management guide
browser.close() Closes the browser and all associated pages. The process owns the browser and is finished with it. Puppeteer Browser.close() API
browser.disconnect() Disconnects Puppeteer from the browser; it does not shut down the browser or close its pages. Use when detaching from a browser intended to remain alive, not as final cleanup for a browser your job must terminate. Puppeteer browser management guide

Standalone screenshot script: close the browser in finally

For a script that launches its own browser and exits after one capture, wrap the work in try/finally. The screenshot guide’s basic sequence launches a browser, creates a page, captures the screenshot, and closes the browser; the finally block makes that cleanup resilient to errors.

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

const browser = await puppeteer.launch();
try {
  const page = await browser.newPage();
  await page.goto('https://example.com');
  await page.screenshot({path: 'screenshot.png'});
} finally {
  await browser.close();
}

Save this as an ES module (for example, capture.js in a project configured with "type": "module") and run it in an environment where Puppeteer is installed. Replace the target URL and output path as needed. Awaiting the screenshot before cleanup makes the intended order explicit. Puppeteer documents screenshot synchronization with page creation and closure within a BrowserContext, so there is no need to race cleanup against an unfinished capture. Puppeteer screenshot guide · Page.screenshot() API

#1 Best Overall
Sale
havit HV-F2056 Laptop Cooling Pad for 15.6-17 Inch Laptops, Black | Three quiet USB-powered fans circulate air below the laptop, two height settings improve viewing and typing comfort
  • Ultra-Portable: Slim, portable, and light weight allowing you to protect your investment wherever you go
  • Ergonomic Comfort: Doubles as an ergonomic stand with two adjustable height settings
  • Optimized for Laptop Carrying: The metal mesh provides your laptop with a stable laptop carrying surface
  • Ultra-Quiet Fans: Three ultra-quiet fans create a noise-free environment for you
  • Extra Usb Ports: Extra USB port and power switch design allows for connecting more USB devices. Warm Tips: The packaged cable is USB to USB connection. Type C connection devices need to prepare an Type C to USB adapter

Long-lived browser: isolate and close each job

If a service keeps one browser open for multiple screenshot jobs, closing that browser after every capture defeats reuse. Instead, put each job’s pages in an isolated context and close that context when the job completes. The browser can then serve another task.

const context = await browser.createBrowserContext();
try {
  const page = await context.newPage();
  await page.goto('https://example.com');
  await page.screenshot({path: 'screenshot.png'});
} finally {
  await context.close();
}

The snippet assumes browser is an already-launched browser owned by the service. If using the default context instead, close the individual page with await page.close(); do not try to close the default context. Puppeteer browser management guide

Rank #2
Sale
Kootek Laptop Cooling Pad Cooler Stand with 5 Quiet Fans for 12"-17" Laptop
  • Dual USB Hub: With a built-in dual USB hub, the laptop fan enables you to connect additional USB devices to your laptop, providing extra connectivity options for your peripherals. Warm tips: The packaged cable is a USB-to-USB connection. Type C connection devices require a Type C to USB adapter. Please plug the cooling pad's USB cable into a 5V 1A adapter for best performance; otherwise, the fans may fail to spin or run at very low speed.
  • Whisper-Quiet Operation: Enjoy a noise-free and interference-free environment with super quiet fans, allowing you to focus on your work or entertainment without distractions.
  • Enhanced Cooling Performance: The laptop cooling pad features 5 built-in fans (big fan: 4.72-inch, small fans: 2.76-inch), all with blue LEDs. 2 On/Off switches enable simultaneous control of all 5 fans and LEDs. Simply press the switch to select 1 fan working, 4 fans working, or all 5 working together.
  • Ergonomic Design: The laptop cooling stand also serves as an ergonomic stand, offering 6 adjustable height settings that enable you to customize the angle for optimal comfort during gaming, movie watching, or working for extended periods. Ideal gift for both the back-to-school season and Father's Day.
  • Secure and Universal Compatibility: Designed with 2 stoppers on the front surface, this laptop cooler prevents laptops from slipping and keeps 12-17 inch laptops—including Apple Macbook Pro Air, HP, Alienware, Dell, ASUS, and more—cool and secure during use.

Dispose ElementHandles returned by selectors

Closing pages is not the only cleanup to consider. Lower-level selector calls such as waitForSelector() return an ElementHandle. Dispose of a handle once it is no longer needed:

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.
const element = await page.waitForSelector('div > .class-name');
try {
  await element?.click();
} finally {
  await element?.dispose();
}

The optional chaining handles a nullable result in this example; adapt error handling to your selector and Puppeteer version. Puppeteer’s page-interactions guide explicitly says the resulting handle must be disposed to prevent memory leaks. Puppeteer page interactions guide

Rank #3
Easy Cloud Computer Fan with AC Plug, 120mm Variable Speed Axial Muffin PC Fan with Controller 120V 110V 220V Small 12V Case Cooling for PC Server Cabinet DVR TV Router Receiver Xbox Greenhouse
  • 【Speed Controllable】Easy Cloud axial fan 120v allows you to freely adjust the computer cooling fan speed according to your needs. This flexibility allows you to adjust fan operation to a level that best suits your environment, whether you require powerful cooling or a quiet work environment
  • 【AC Plug】Dual-ball bearings have a lifespan of 50,000 hours. Easy Cloud small computer fan 120mm comes with 3V to 12V multi-speed controller, increases maximum axial fan speed and powers the muffin fan from an AC outlet. Just plug it into an outlet and start the 120mm pc fan
  • 【Applicability】Designed to meet the cooling and ventilation needs of a variety of devices, including pcs, game consoles, appliances, entertainment equipment, solar equipment and more, this 120mm vent fan provides effective silent cooling and is also an ideal replacement for your existing 12v computer fan. No matter what type of equipment you have, this 120mm case fan ensures it stays at the right operating temperature, improving performance and extending life
  • 【Parameter】120 x 120 x 25 mm ( 4.72 x 4.72 x 0.98 inches. ) | Rated Voltage: 12V | Airflow: 95.8 ±10M | Rated Current: 0.3A | Bearings: Dual Ball | Speed: 700RPM to 2800RPM | Power: 3.3W | Noise: <41dB
  • 【Customer Support】We strive to offer the excellent services out of your expectations. If you have any problems with our product, please feel free to contact us at anytime

Diagnose growing memory without assuming a cause

Apply the documented cleanup rules at the ownership boundary, then investigate the application if memory still grows. The Puppeteer guidance cited here identifies handle disposal and resource closure as relevant lifecycle practices, but gives no general memory-reduction figure and does not establish that unclosed pages explain every memory increase.

  • Check that every screenshot promise is awaited before its page or context is closed.
  • Check that each task closes its page or isolated context, and that a standalone process closes the browser it launched.
  • Review selector code for retained ElementHandle objects and dispose of handles when finished.
  • Do not count browser.disconnect() as process cleanup if the browser should stop.

Troubleshooting cleanup problems

The browser process remains after the script ends

If the script owns the launched browser, call and await browser.close() in a finally block. Disconnecting the client leaves the browser running by design.

Rank #4
Sale
ChillCore Laptop Cooling Pad, RGB Lights Laptop Cooler 9 Fans for 15.6-19.3 Inch Laptops, Gaming Laptop Fan Cooling Pad with 8 Height Stands, 2 USB Ports - A21 Blue
  • 9 Super Cooling Fans: The 9-core laptop cooling pad can efficiently cool your laptop down, this laptop cooler has the air vent in the top and bottom of the case, you can set different modes for the cooling fans.
  • Ergonomic comfort: The gaming laptop cooling pad provides 8 heights adjustment to choose.You can adjust the suitable angle by your needs to relieve the fatigue of the back and neck effectively.
  • LCD Display: The LCD of cooler pad readout shows your current fan speed.simple and intuitive.you can easily control the RGB lights and fan speed by touching the buttons.
  • 10 RGB Light Modes: The RGB lights of the cooling laptop pad are pretty and it has many lighting options which can get you cool game atmosphere.you can press the botton 2-3 seconds to turn on/off the light.
  • Whisper Quiet: The 9 fans of the laptop cooling stand are all added with capacitor components to reduce working noise. the gaming laptop cooler is almost quiet enough not to notice even on max setting.

Other jobs stop working after cleanup

The job may be closing a shared browser instead of only its page or isolated context. In a multi-job service, close the task’s context or page and keep the shared browser open.

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

Screenshot output is missing or incomplete

Make sure the screenshot call is awaited and inspect whether navigation or capture throws before cleanup. In the standalone pattern, the finally block still closes the browser after such an error; handle or report the original error in the surrounding job logic.

Best Value
KeiBn Laptop Cooling Pad, Gaming Laptop Cooler 2 Fans for 10-15.6 Inch Laptops, 5 Height Stands, 2 USB Ports (S039)
  • 【Efficient Heat Dissipation】KeiBn Laptop Cooling Pad is with two strong fans and metal mesh provides airflow to keep your laptop cool quickly and avoids overheating during long time using.
  • 【Ergonomic Height Stands】Five adjustable heights desigen to put the stand up or flat and hold your laptop in a suitable position. Two baffle prevents your laptop from sliding down or falling off; It's not just a laptop Cooling Pad, but also a perfect laptop stand.
  • 【Phone Stand on Side】A hideable mobile phone holder that can be used on both sides releases your hand. Blue LED indicator helps to notice the active status of the cooling pad.
  • 【2 USB 2.0 ports】Two USB ports on the back of the laptop cooler. The package contains a USB cable for connecting to a laptop, and another USB port for connecting other devices such as keyboard, mouse, u disk, etc.
  • 【Universal Compatibility】The light and portable laptop cooling pad works with most laptops up to 15.6 inch. Meet your needs when using laptop home or office for work.

Memory continues to rise despite closing pages

Page closure is not proof that all application memory growth is fixed. Audit retained handles and other resources in your own job lifecycle; the cited Puppeteer guidance does not promise a specific memory reduction or diagnose every leak.

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

Or skip the browser setup

ScreenshotNeo provides a website screenshot API, so a single GET request can return an image or PDF without managing a Puppeteer browser in your script. For example, save the response as a WebP file:

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

See the ScreenshotNeo documentation for the request options. Cookie banners, popups and chat widgets are removed before capture; bot checks, blank pages and failed loads are never billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000. Learn about ScreenshotNeo or sign up for 1,000 free screenshots a month, no card required.

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

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.