October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Screenshot a Webpage with Playwright in Go

A working Go example for taking a webpage screenshot with playwright-go, plus full-page options, readiness guidance, cleanup, and troubleshooting.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use the playwright-go library: install its matching Playwright driver and browser, start Chromium, open a page, navigate to the URL, then call page.Screenshot with a file path. Set FullPage when you need content below the fold, and close both the browser and Playwright runtime when finished.

Install playwright-go and its browser

Add the Go dependency and install the Playwright driver and browser binaries. The project README documents this installation flow and warns that the driver version must correspond to the playwright-go version recorded in your go.mod; a minor library upgrade can require a specific driver version. Follow the README for the exact command for your chosen version rather than copying a version placeholder as if it were a current release.

As an Amazon Associate I earn from qualifying purchases.

After installation, verify that the driver and Chromium are available in the environment where the Go program will run. A machine with the Go package alone is not sufficient: Playwright also needs its driver and browser installation.

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

Capture a webpage to a PNG file

This complete example opens https://example.com, saves the visible viewport as screenshot.png, checks errors, and closes the browser and Playwright runtime on the success path.

#1 Best Overall
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB | 1920×1080 LED Monitor, 4ms GtG, Adaptive Sync, HDMI 1.4, Tilt Adjust, Low Blue Light, 4yr Advance Replacement Warranty
  • 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
package main

import (
    "log"

    "github.com/mxschmitt/playwright-go"
)

func main() {
    pw, err := playwright.Run()
    if err != nil {
        log.Fatalf("could not launch playwright: %v", err)
    }

    browser, err := pw.Chromium.Launch()
    if err != nil {
        log.Fatalf("could not launch Chromium: %v", err)
    }

    page, err := browser.NewPage()
    if err != nil {
        log.Fatalf("could not create page: %v", err)
    }

    if _, err = page.Goto("https://example.com"); err != nil {
        log.Fatalf("could not navigate: %v", err)
    }

    if _, err = page.Screenshot(playwright.PageScreenshotOptions{
        Path: playwright.String("screenshot.png"),
    }); err != nil {
        log.Fatalf("could not create screenshot: %v", err)
    }

    if err = browser.Close(); err != nil {
        log.Fatalf("could not close browser: %v", err)
    }
    if err = pw.Stop(); err != nil {
        log.Fatalf("could not stop Playwright: %v", err)
    }
}

Run the program from a directory where it can write the output file. On success, the screenshot is written to that path. For production code, ensure cleanup also runs when navigation or capture fails; the example reports errors at each step, but its explicit cleanup calls are on the success path.

Choose what the screenshot should include

Visible viewport

The example leaves FullPage unset, so it captures the currently visible page area. This is appropriate for a browser-window view or when the page is already sized to the content you need.

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

Full scrollable page

Set FullPage to true to capture the full scrollable page instead of only the viewport:

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.
if _, err = page.Screenshot(playwright.PageScreenshotOptions{
    Path:     playwright.String("full-page.png"),
    FullPage: playwright.Bool(true),
}); err != nil {
    log.Fatalf("could not create screenshot: %v", err)
}

Full-page capture is useful for long articles and landing pages. Pages that load images or other content only as you scroll may need additional readiness handling before capture; otherwise, content that has not loaded may be missing.

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.

A single element

When you only need a particular card, chart, or other element, use Playwright’s locator-level screenshot capability rather than capturing the whole page and cropping afterward. The general Playwright guide documents this approach, but check the exact locator screenshot method signature in the version of the Go library you installed.

Image bytes instead of a file

Playwright’s screenshot API can return image bytes for processing or storage without first writing a file. Check the return value and signature exposed by your installed playwright-go version before using it; the example above uses the path option for a straightforward file output.

Rank #4
Sale
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor | 100Hz, Game Mode, Advanced Eye Comfort, HDMI and D-sub Ports (LS27D366GANXZA)
  • 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

Wait for the page state you need

A successful navigation does not guarantee that every dynamic element is ready for capture. The maintained Go example navigates with a DOMContentLoaded wait condition. For a page that fills in content afterward, wait for the relevant selector or choose an appropriate readiness condition before taking the screenshot. Avoid relying on an arbitrary short delay when a specific element can indicate that the page is ready.

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

The Go example and version-specific navigation details are in the playwright-go screenshot example. For broader screenshot behavior, see the Playwright Screenshots guide.

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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Useful screenshot options

Beyond the file path and full-page setting, Playwright documents options for clipping to a rectangle, scaling in CSS pixels or device pixels, and controlling animation, caret visibility, masking, and background. These options change the captured output; consult the Page API and the installed Go package’s API for the supported option names and types in your version.

Keep the initial implementation minimal and add options only for a concrete need. For example, choose full-page capture for below-the-fold content or a locator screenshot when the page contains only one target element worth saving.

Cleanup and reliability

The program starts two resources: the Playwright runtime and a browser. Close the browser and stop Playwright after capture so repeated or long-running jobs do not leave resources running. In code that may return early, arrange cleanup immediately after each successful start—using deferred cleanup where appropriate—so a navigation or screenshot error does not bypass it. If the browser fails to launch, first confirm the driver and browser installation and that the driver matches the library version in go.mod.

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

Common problems

  • Driver or browser launch failure: Install the Playwright driver and Chromium in the runtime environment, and confirm the driver version matches the playwright-go version in go.mod.
  • Navigation error: Check that the URL is reachable from the machine running the program and inspect the returned error before attempting capture.
  • Screenshot file is missing: Check the returned screenshot error and ensure the process can write to the requested path and its parent directory.
  • Screenshot is blank or incomplete: Confirm that navigation succeeded and wait for the page content you need, especially if it is rendered after the initial document load or loaded while scrolling.
  • Only the top of a long page appears: Set FullPage: playwright.Bool(true); the default viewport capture does not include the entire scrollable document.
  • Cleanup is skipped after a failure: Put browser and runtime cleanup on an error-safe path immediately after each resource starts, rather than only after a successful screenshot.

Or skip the browser setup

ScreenshotNeo offers a website screenshot API and MCP server. A single GET request can return an image or PDF, without installing Playwright and a browser for this capture:

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 API details. Cookie banners, newsletter popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots, and the Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for free.

Frequently Asked Questions

Which Go package does this example use?

It uses github.com/mxschmitt/playwright-go.

Does the basic example capture the entire webpage?

No. It captures the visible viewport; set FullPage to true for the full scrollable page.

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.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

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.

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
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver 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.