How to Take Screenshots with pyppeteer in Python

Guide to taking screenshots with pyppeteer in Python. Learn the basics, full page captures, and why you should migrate to Playwright.

Blog post 2 min read

Written by

Dmytro Krasun

Published on

Important Note: pyppeteer is no longer actively maintained. The last major update was in 2020. For new projects, I strongly recommend using Playwright instead. This guide is for those maintaining legacy code.

pyppeteer is a Python port of Puppeteer, the Node.js browser automation library. While it was groundbreaking when released, it hasn’t kept up with browser changes.

Installation

Terminal window
pip install pyppeteer

On first run, pyppeteer downloads Chromium automatically.

Basic Screenshot

import asyncio
from pyppeteer import launch
async def take_screenshot():
browser = await launch()
page = await browser.newPage()
await page.goto('https://example.com')
await page.screenshot({'path': 'screenshot.png'})
await browser.close()
asyncio.get_event_loop().run_until_complete(take_screenshot())

Full Page Screenshots

import asyncio
from pyppeteer import launch
async def full_page_screenshot():
browser = await launch()
page = await browser.newPage()
await page.goto('https://example.com')
await page.screenshot({
'path': 'fullpage.png',
'fullPage': True
})
await browser.close()
asyncio.get_event_loop().run_until_complete(full_page_screenshot())

Viewport Settings

async def screenshot_with_viewport():
browser = await launch()
page = await browser.newPage()
# Set viewport
await page.setViewport({
'width': 1920,
'height': 1080
})
await page.goto('https://example.com')
await page.screenshot({'path': 'screenshot.png'})
await browser.close()

Element Screenshots

async def element_screenshot():
browser = await launch()
page = await browser.newPage()
await page.goto('https://example.com')
element = await page.querySelector('.hero-section')
await element.screenshot({'path': 'element.png'})
await browser.close()

Waiting for Content

async def screenshot_with_wait():
browser = await launch()
page = await browser.newPage()
await page.goto('https://example.com')
# Wait for selector
await page.waitForSelector('.main-content')
# Or wait for navigation
await page.waitForNavigation()
await page.screenshot({'path': 'screenshot.png'})
await browser.close()

Headless Mode

async def headless_screenshot():
browser = await launch(headless=True) # Default is True
page = await browser.newPage()
await page.goto('https://example.com')
await page.screenshot({'path': 'screenshot.png'})
await browser.close()

PDF Generation

One advantage pyppeteer shares with Playwright:

async def generate_pdf():
browser = await launch()
page = await browser.newPage()
await page.goto('https://example.com')
await page.pdf({
'path': 'page.pdf',
'format': 'A4'
})
await browser.close()

Why Migrate to Playwright?

FeaturepyppeteerPlaywright
MaintainedNo (since 2020)Yes (actively)
Browser supportChromium onlyChrome, Firefox, Safari
Sync APINoYes
Auto-waitBasicAdvanced
DocumentationOutdatedExcellent
CommunitySmallLarge

Migration Guide

Most pyppeteer code translates to Playwright with minor changes:

pyppeteer

import asyncio
from pyppeteer import launch
async def main():
browser = await launch()
page = await browser.newPage()
await page.goto('https://example.com')
await page.screenshot({'path': 'screenshot.png', 'fullPage': True})
await browser.close()
asyncio.get_event_loop().run_until_complete(main())

Playwright

import asyncio
from playwright.async_api import async_playwright
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch()
page = await browser.new_page()
await page.goto('https://example.com')
await page.screenshot(path='screenshot.png', full_page=True)
await browser.close()
asyncio.run(main())

Key differences:

  • launch()p.chromium.launch()
  • newPage()new_page()
  • {'path': ...}path=... (keyword args)
  • fullPagefull_page
  • asyncio.get_event_loop().run_until_complete()asyncio.run()

Common Issues with pyppeteer

Chromium Version Mismatch

pyppeteer downloads an old Chromium version that may not work with modern websites:

# Workaround: specify executable path
browser = await launch(executablePath='/path/to/chrome')

Connection Errors

# Increase timeout
browser = await launch(timeout=60000)

Memory Leaks

Long-running pyppeteer processes often leak memory. Restart the browser periodically:

# Close and reopen browser every N screenshots
if screenshot_count % 100 == 0:
await browser.close()
browser = await launch()

Summary

pyppeteer works for simple use cases but has significant limitations:

  • Not actively maintained
  • Uses outdated Chromium
  • Limited browser support
  • Basic async patterns

Recommendation: Migrate to Playwright for better features, active maintenance, and modern browser support.

Frequently Asked Questions

If you read the article, but still have questions. Please, check the most frequently asked. And if you still have questions, feel free reach out at support@screenshotone.com.

Is pyppeteer still maintained?

No, pyppeteer is no longer actively maintained. The last significant update was in 2020. For new projects, use Playwright instead, which is actively developed and has better features.

What is the difference between pyppeteer and Playwright?

Both are browser automation libraries, but Playwright is actively maintained, supports multiple browsers natively, has better async support, and includes more features. pyppeteer only supports Chromium and is outdated.

How to migrate from pyppeteer to Playwright?

The APIs are similar. Replace 'from pyppeteer import launch' with 'from playwright.async_api import async_playwright', and adjust method names slightly. Most code translates directly.

Read more Screenshot rendering

Interviews, tips, guides, industry best practices, and news.

View all posts
Let's build a screenshot API

Let's build a screenshot API

Two years have passed since the launch of ScreenshotOne, and I want to do a fun coding exercise and build a tiny subset of what the API is today, but from scratch.

Read more
3 best screenshot APIs in 2026

3 best screenshot APIs in 2026

The truth is, that there is no single best screenshot API that fits everyone. But some APIs stand out and shine when compared to others. Also, it depends on your use case and needs which must be included in considering what API to use.

Read more

Automate website screenshots

Exhaustive documentation, ready SDKs, no-code tools, and other automation to help you render website screenshots and outsource all the boring work related to that to us.