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

Use a real Chromium browser and the maintained chromedp package. Navigate to the page, call chromedp.FullScreenshot(&png, 100), and write the returned bytes with os.WriteFile. Quality 100 selects PNG; lower values select JPEG. Go image libraries alone cannot render modern HTML, CSS, JavaScript, or web fonts.

Complete Go example: save a full webpage as PNG

Create a module, add chromedp, and ensure a Chromium-based browser is available on the machine running the program.

go mod init webpage-shot
go get github.com/chromedp/chromedp

Save this as main.go:

package main

import (
    "context"
    "log"
    "os"

    "github.com/chromedp/chromedp"
)

func main() {
    ctx, cancel := chromedp.NewContext(context.Background())
    defer cancel()

    var png []byte
    err := chromedp.Run(ctx,
        chromedp.Navigate("https://example.com"),
        chromedp.FullScreenshot(&png, 100),
    )
    if err != nil {
        log.Fatal(err)
    }
    if err := os.WriteFile("page.png", png, 0o644); err != nil {
        log.Fatal(err)
    }
}

Run go run .. A successful run creates page.png in the current directory. FullScreenshot captures the entire page rather than only the visible viewport. The byte slice is already encoded image data, so write it in binary mode; do not convert it to a string.

Choose the capture scope

Current viewport

Use chromedp.CaptureScreenshot when you need exactly what is visible in the browser window:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
var buf []byte
err := chromedp.Run(ctx,
    chromedp.Navigate("https://example.com"),
    chromedp.CaptureScreenshot(&buf),
)
if err != nil { log.Fatal(err) }
if err := os.WriteFile("viewport.png", buf, 0o644); err != nil { log.Fatal(err) }

This is not a full-page capture; content below the viewport is excluded.

One element by CSS selector

chromedp.Screenshot captures the first matching element. chromedp.NodeVisible makes the action wait for a visible node:

var element []byte
err := chromedp.Run(ctx,
    chromedp.Navigate("https://example.com"),
    chromedp.Screenshot("#content", &element, chromedp.NodeVisible),
)
if err != nil { log.Fatal(err) }
if err := os.WriteFile("content.png", element, 0o644); err != nil { log.Fatal(err) }

Use a stable selector such as an ID or data attribute. A selector matching nothing, or matching an element that never becomes visible, causes the action to fail.

Full page versus viewport dimensions

FullScreenshot is the simplest complete-page path. For more specialized work, the Chrome DevTools Protocol method Page.captureScreenshot supports an image format, a clip rectangle, and captureBeyondViewport. The chromedp CDP binding returns decoded image bytes that you can write to disk just like the examples above.

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

PNG, JPEG, scale, and clipping

PNG selection

Pass quality 100 to FullScreenshot to keep PNG output:

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
chromedp.FullScreenshot(&png, 100)

Values below 100 select JPEG output. If your downstream pipeline requires PNG transparency or lossless pixels, keep the value at 100 and use a .png filename.

Change page scale

chromedp.ScreenshotScale changes the page scale factor. Apply it when you need a higher- or lower-density capture, while remembering that a larger scale produces more pixels and usually larger files:

var buf []byte
err := chromedp.Run(ctx,
    chromedp.ScreenshotScale(2),
    chromedp.CaptureScreenshot(&buf),
)

Choose the scale deliberately for the consumer of the image (for example, a retina preview versus a compact archive).

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

Clip a region with CDP

When a viewport or element screenshot is not enough, construct a CDP capture request with a clip rectangle and enable capture beyond the viewport where required. This is useful for a precise x/y/width/height region, but it also means you must manage page dimensions and device scale yourself. The high-level element and full-page actions are less error-prone for ordinary captures.

Wait for dynamic pages before capturing

Navigation completing does not guarantee that a single-page application, images, or web fonts have finished rendering. Add a wait action that reflects the page’s real readiness condition: a selector that appears after rendering, a deliberate delay, or a network-idle strategy implemented with the chromedp actions appropriate to your application. For an element capture, chromedp.NodeVisible combines selection and visibility checking.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Keep waits bounded with a context timeout so a broken page cannot hold a worker forever:

ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
ctx, cancel = chromedp.NewContext(ctx)
defer cancel()

Import time when using this pattern. A timeout is an operational safeguard, not a guarantee that every page has loaded correctly; validate the resulting bytes and, when appropriate, inspect the page for an expected element.

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

Reusable capture function

Putting navigation, capture, and persistence behind a function makes batch jobs easier to test and lets callers choose full-page or viewport output:

func saveFullPNG(parent context.Context, url, filename string) error {
    ctx, cancel := chromedp.NewContext(parent)
    defer cancel()

    var data []byte
    if err := chromedp.Run(ctx,
        chromedp.Navigate(url),
        chromedp.FullScreenshot(&data, 100),
    ); err != nil {
        return err
    }
    return os.WriteFile(filename, data, 0o644)
}

Call it with a parent context that has a deadline. Return errors to the caller instead of logging inside library code; the command-line entry point can decide whether to retry or exit.

Browser and runtime considerations

Chromium is a prerequisite

chromedp drives a Chromium-based browser through the DevTools Protocol. A Go-only image encoder cannot execute JavaScript, apply responsive CSS, or lay out the page. On a developer workstation, verify that the browser can launch under the same account as the Go process. In containers or CI, provide a compatible Chromium installation and the sandbox configuration required by that environment.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Concurrency and cleanup

Create a context per independent capture, defer its cancellation, and close resources even when navigation fails. Reusing a browser allocator can reduce startup overhead in a long-running worker, while separate browser contexts keep cookies and page state isolated. Limit concurrent tabs to what the host can support; no authoritative speed, memory, or PNG-size benchmark is established here, so measure your own pages and workload.

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

Security boundaries

Do not pass untrusted URLs to a privileged browser without considering server-side request forgery, local-file access, credentials, and network reachability. Supply only the headers, cookies, and browser permissions that the capture actually needs, and isolate screenshot workers from sensitive internal networks.

Common failures and fixes

“exec: executable file not found” or browser launch errors

  • Cause: Chromium is missing or not discoverable.
  • Fix: Install a supported Chromium-based browser, run it under the service account, and configure chromedp’s allocator options for the executable path when it is not on PATH.

Context deadline exceeded

  • Cause: The page, a resource, or your wait condition did not finish before the deadline.
  • Fix: Set a realistic timeout, wait for a specific readiness selector instead of an arbitrary long sleep, and retry only transient failures.

Blank or incomplete image

  • Cause: Capture happened before client-side rendering, lazy images, fonts, or animations settled.
  • Fix: Wait for the content selector, trigger the page state your application requires, and use a bounded delay only when no reliable selector exists.

Element selector failed

  • Cause: The selector is wrong, the element is inside a frame, or it never becomes visible.
  • Fix: Confirm the selector in browser developer tools, account for iframe context, and use chromedp.NodeVisible with a timeout.

Output is JPEG instead of PNG

  • Cause: A quality value below 100 was passed to FullScreenshot, or a lower-level CDP format was set to JPEG.
  • Fix: Pass 100, request PNG at the protocol layer, and keep the filename extension consistent.

Permission denied while writing

  • Cause: The process cannot write the destination directory.
  • Fix: Use a writable absolute or working-directory path and check filesystem ownership and permissions. os.WriteFile with 0o644 creates a normal user-readable file when the directory permits it.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When a hosted screenshot API is a better fit

Local chromedp gives you control, but every deployment must supply and maintain a browser runtime, waits, isolation, storage, and failure handling. For scheduled captures, CI pipelines, or services that should not manage Chromium, ScreenshotNeo is the first API to try: it produces clean shots, bills only clean shots, and its paid entry plan is $5 for 3,000 shots.

Or skip the browser setup

ScreenshotNeo accepts one GET request and returns PNG, JPEG, WebP, or PDF. The following cURL call saves a PNG-compatible image response (the API chooses the response format according to the request options):

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

See the complete parameter list and format controls in the ScreenshotNeo documentation. Equivalent clients:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Python

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)

Node.js

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));

Before capture, ScreenshotNeo accepts cookie and consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be disabled. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and whether the request was billed. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for the free 1,000-shot plan.

Operational checklist

  • Confirm Chromium launches under the deployment account.
  • Use a context timeout and always cancel it.
  • Choose viewport, element, or full-page capture explicitly.
  • Pass quality 100 when PNG is required.
  • Wait for a real readiness condition on dynamic pages.
  • Write returned bytes directly with a binary-safe function.
  • Log URL, duration, output path, and error category without logging secrets.
  • Test representative pages in the same OS, browser, and container image used in production.

Frequently Asked Questions

Can chromedp capture only the visible browser area?

Yes. Use chromedp.CaptureScreenshot; use chromedp.FullScreenshot for the complete page.

Does FullScreenshot always produce PNG?

It produces PNG when quality is 100. Lower quality values select JPEG.

Can I screenshot an HTML element in Go?

Yes. Pass its CSS selector and a byte slice to chromedp.Screenshot, commonly with chromedp.NodeVisible.

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.

Why is a browser required?

Modern webpages need a rendering engine to execute JavaScript and lay out HTML and CSS; image libraries do not perform that work.

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.