Capture screenshots and PDFs from web pages using headless Chrome via CDP.
Maintained. Last release 13 days ago, commits in 4 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install nokapnokap captures screenshots and PDFs from web pages (or local HTML) using headless Chrome via the Chrome DevTools Protocol. It doesn't need Selenium or Playwright. Its only runtime dependencies are websockets and click.
Installation
pip install nokap
nokap uses the Chrome or Chromium already on your system and will hunt it down pretty quickly. If you don't have one, or you're running inside a sandbox where full Chrome can't start (such as a coding agent's sandbox on macOS), install Chrome's standalone headless build:
nokap install-chrome
This downloads chrome-headless-shell from Chrome for Testing into nokap's cache, and nokap uses it from then on. Nothing is downloaded unless you run this command. Check your setup with nokap doctor.
Quick Start
import nokap
# Screenshot a URL
nokap.webshot("https://example.com", "example.png")
# Save as PDF
nokap.webshot("https://example.com", "example.pdf")
# Screenshot with a CSS selector (captures just that element)
nokap.webshot("https://example.com", "header.png", selector="h1")
# From an HTML string (great for table libraries)
nokap.from_html("<h1>Hello, world!</h1>", "hello.png")
API
nokap.webshot()
Take a screenshot or PDF of a web page.
nokap.webshot(
url, # URL or local file path
file="webshot.png", # Output path (.png, .jpg, .webp, .pdf)
*,
vwidth=992, # Viewport width (px)
vheight=744, # Viewport height (px)
selector=None, # CSS selector to capture
cliprect=None, # Clip rectangle (x, y, width, height)
expand=0, # Padding around selector (px)
delay=0.2, # Wait after page load (seconds)
zoom=1, # Scale factor (2 = retina)
useragent=None, # Custom User-Agent string
renderer=None, # Use an existing Renderer
)