Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Use Playwright’s Python API to render HTML in a browser and save the resulting pixels as a PNG. For an HTML string, load it into a page and call page.screenshot(path="output.png"); for a website, navigate to its URL first. Add full_page=True for the full scrollable page, or capture a specific element with a locator. This approach is suited to HTML that depends on browser layout or JavaScript.
What “render HTML to PNG” means
HTML is a document description, not an image. To convert it to PNG, a renderer must interpret the HTML and CSS, lay out the page, and rasterize the visible result. Playwright controls browser engines—Chromium, Firefox, and WebKit—through one Python API, then captures the rendered page as an image.
A screenshot represents a particular browser state and capture area. A viewport screenshot records the visible region; a full-page screenshot extends to the page’s scrollable height; an element screenshot crops to a selected element. Dynamic content, external assets, fonts, and viewport dimensions can all affect what appears.
Install Playwright and a browser
Playwright requires its Python package and browser binaries. The documentation consulted for this guide establishes the screenshot APIs, but not current installation commands or system dependencies. Use the official Playwright Python installation guide for the commands and setup appropriate to your operating system and environment, then confirm that the browser you intend to use launches successfully.
#1 Best Overall
Keep the Python package and installed browser binaries aligned with the version and environment you deploy. A local installation that works on a developer’s machine may still need browser setup and operating-system dependencies in a container or server environment.
Render an HTML string and save a PNG
For a small, self-contained document, create a page, supply the HTML, and save a screenshot. This synchronous example follows the documented Playwright page and screenshot API. The use of set_content() is a practical way to provide an HTML string; the code below has not been independently executed for this article.
from playwright.sync_api import sync_playwright
html = """
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style>
body { font-family: sans-serif; padding: 24px; }
h1 { color: #174ea6; }
</style>
</head>
<body>
<h1>Hello, world!</h1>
<p>Rendered from HTML with Python.</p>
</body>
</html>
"""
with sync_playwright() as p:
browser = p.chromium.launch()
try:
page = browser.new_page(viewport={"width": 1000, "height": 700})
page.set_content(html)
page.screenshot(path="output.png", full_page=True)
finally:
browser.close()
The output path determines where the PNG is written. The viewport is set explicitly so that the layout has known dimensions; full_page=True asks Playwright to capture the entire scrollable page rather than just that viewport. If you omit full_page=True, the screenshot is limited to the viewport.
The try/finally block closes the browser even if page creation or capture raises an exception. For long-running applications, also consider how your application manages page and browser lifetimes so failed requests do not leave resources open.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Render a website URL
For a live page, navigate to its URL instead of supplying an HTML string. Choose a page-ready condition that fits the site: there is no single wait strategy appropriate for every application. A page can reach a navigation state while JavaScript is still updating content or while images and other assets are still loading.
Rank #2
from playwright.sync_api import sync_playwright
url = "https://example.com"
with sync_playwright() as p:
browser = p.chromium.launch()
try:
page = browser.new_page(viewport={"width": 1365, "height": 900})
page.goto(url)
page.screenshot(path="page.png", full_page=True)
finally:
browser.close()
For pages with client-side rendering or delayed assets, add an appropriate readiness check before the screenshot—for example, wait for a selector that appears when the required content is ready. A fixed delay can help with a known, bounded animation or update, but it is not a universal guarantee that all resources have loaded. Avoid treating network idle or any other single state as proof that every site’s visual content is complete.
Choose the right capture area and output
Capture the viewport
Use page.screenshot(path="viewport.png") for the visible browser viewport. Set its width and height when predictable layout matters. This is useful for a dashboard panel, a preview, or a screenshot that must have consistent dimensions.
Capture the full page
Use page.screenshot(path="full.png", full_page=True) to capture the full scrollable page. This is not the same as increasing the browser viewport: Playwright captures beyond the initially visible area. Pages that load content only as the user scrolls may need additional handling to make that content appear before capture; there is no universal lazy-loading procedure established here.
Capture one element
When only a chart, card, or other region is needed, target a stable selector and take a locator screenshot:
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch()
try:
page = browser.new_page()
page.goto("https://example.com")
card = page.locator(".report-card")
card.screenshot(path="report-card.png")
finally:
browser.close()
Replace .report-card with a selector that identifies the desired element on the page. If the locator does not match, or matches an unexpected element, correct the selector or wait for the intended content before capture.
Save bytes instead of a file
The screenshot API can return image bytes when you do not pass a file path. This lets an application send the PNG in a response, store it through another library, or pass it into an image-processing pipeline:
png_bytes = page.screenshot()
# Pass png_bytes to the storage or image-processing code used by your application.
PNG is the screenshot default. The API also supports JPEG and WebP, and can capture at CSS-pixel or device-pixel scale. PNG does not use the screenshot quality setting. Transparent background is supported in applicable cases; check the Playwright screenshot documentation for the options and conditions for your installed version.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Control layout before capture
For repeatable results, treat the browser state as part of the input—not just the HTML source. Set a viewport when the target layout depends on screen width, and wait for the specific content that must be visible. If the page uses JavaScript or remote assets, ensure those elements are ready before taking the screenshot.
- Viewport: Choose dimensions that produce the intended responsive layout.
- Capture scope: Decide whether the output should show the viewport, full page, or one element.
- Content readiness: Wait for a meaningful selector or application state when needed.
- Output format: Keep PNG for lossless raster capture; consider JPEG or WebP if those formats better fit the destination.
- Browser engine: Playwright provides Chromium, Firefox, and WebKit control. Select an engine appropriate to the browser behavior you need.
These are operational choices, not a promise that screenshots will be pixel-identical across engines, environments, or page versions. Verify the rendered output against the actual target HTML and deployment setup.
Common problems and fixes
The browser does not launch
The Python package alone may not be enough; the browser binaries also need to be installed in the environment. Follow the official installation guide for your platform and confirm the chosen browser is available where the script runs. In containers and servers, check that the deployment environment includes the required browser setup.
The PNG is blank or missing expected content
The page may not have reached the state you intended to capture. For a remote page, check navigation and the browser’s visible page state, then wait for the specific content selector or application condition that matters. If content loads only after scrolling, a full-page capture by itself does not establish that the site has loaded every lazy asset.
The screenshot has the wrong dimensions
A default or unintended viewport can trigger a different responsive layout than the one you want. Set an explicit viewport before navigating or capturing, and decide whether the expected output is viewport-sized or full-page. For a single component, use a locator screenshot rather than cropping the full page afterward.
The capture is clipped
A regular page screenshot records the viewport. Use full_page=True for the full scrollable page, or capture the relevant element directly with a locator. Check whether the page’s content has actually expanded or loaded before capture.
The result changes between runs
Rendered output depends on browser state and the page being rendered. Differences can come from changing page content, delayed JavaScript, remote assets, responsive layout, or renderer versions. Make viewport and readiness conditions explicit, keep the runtime environment consistent, and visually verify the output after version changes.
A historical WeasyPrint example does not work
Do not assume an old PNG method remains available in current releases. WeasyPrint 52.5 documentation includes a write_png API, but the current stable 70.0 API reference inspected for this guide documents PDF output. Confirm the supported route for the exact version you plan to use before building a PNG workflow around WeasyPrint.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsBest Value
Playwright or WeasyPrint?
Choose based on the rendering behavior and output you need, not on an assumed speed or quality ranking. The available documentation does not establish comparative benchmarks.
| Approach | What the documented sources establish | When to consider it |
|---|---|---|
| Playwright Python | Browser automation with Chromium, Firefox, and WebKit; page screenshots, full-page screenshots, and locator screenshots; PNG, JPEG, and WebP options. | When the page needs browser layout or JavaScript-driven behavior, or the capture target is a viewport, full page, or element. |
| WeasyPrint 70.0 | The current stable API reference inspected documents PDF output. | When PDF is the needed output and its rendering behavior suits the document. |
| WeasyPrint 52.5 | Historical documentation includes the write_png API. |
Only when working with that historical version and after checking its compatibility and requirements; do not generalize its PNG API to current releases. |
WeasyPrint’s documentation notes that rendered output can change as versions evolve. Whichever renderer you choose, check the precise version and verify the appearance of the target document. The versions above describe the documentation cited here, not a guarantee about what is latest when you read this.
Or skip the browser setup
If you want a hosted screenshot endpoint instead of installing and running a browser, ScreenshotNeo accepts a URL in one GET request and returns an image or PDF. For a PNG response, the basic cURL request is:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
The example writes a WebP file, matching the supplied code. Change the output name and request options as appropriate for the format you need. See the ScreenshotNeo API documentation for authentication and available parameters.
Recommended Free Tools
ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status in headers. Its MCP server provides screenshot, page-info, and PDF tools for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.
Sign up for the free plan to try 1,000 screenshots a month without a card.
Sources
- Playwright Python: Screenshots
- Playwright Python: Page API
- WeasyPrint 70.0 stable API reference
- WeasyPrint 52.5 API reference
- WeasyPrint API reference in the project repository
Frequently Asked Questions
Can Playwright take a screenshot without writing a file?
Yes. Call page.screenshot() without a path to get image bytes.
Can I capture only part of a page?
Yes. Use a locator for the target element and call its screenshot() method.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Does Playwright support formats other than PNG?
Yes. The screenshot API also supports JPEG and WebP.
Quick Recap
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.

