October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Take a Website Screenshot in Go with chromedp

Use chromedp to capture a viewport, element, or full webpage in Go, then save the image bytes with the correct format and readiness checks.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use chromedp to open a page, choose whether to capture the viewport, a matching element, or the full page, then write the returned image bytes to disk. The right capture action depends on how much of the page you need.

Choose the capture that matches the image you need

Desired result chromedp action What it captures
Visible viewport chromedp.CaptureScreenshot(&buf) The current browser viewport, not content beyond it.
One element chromedp.Screenshot(selector, &buf) The first element matching the selector. It returns an error if no node matches.
Entire page chromedp.FullScreenshot(&buf, quality) A full-page capture that extends beyond the viewport.

The examples below use the official chromedp screenshot API and example: screenshot.go and the screenshot example. They are from the projects’ current main branches, not a version-pinned compatibility matrix; check the APIs against the chromedp version in your Go module.

As an Amazon Associate I earn from qualifying purchases.

Capture and save a full-page screenshot

Create a chromedp context, navigate, run the full-page capture, and save its bytes. This complete example checks errors from both the browser actions and file output:

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

import (
	"context"
	"log"
	"os"

	"github.com/chromedp/chromedp"
)

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

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

Save the file with a .png extension when quality is 100: chromedp’s FullScreenshot selects PNG at that value and JPEG at other quality values from 0 through 100. Use a matching extension such as .jpg for JPEG output. The helper’s implementation and behavior are documented in chromedp’s screenshot source.

Capture only the viewport or a specific element

Visible viewport

To capture only what is currently visible in the browser, replace the full-page action with chromedp.CaptureScreenshot:

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)
}

One matching element

Pass a CSS selector to chromedp.Screenshot to capture the first matching node. For example, replace the capture action above with:

chromedp.Screenshot("main article", &buf)

Keep the surrounding chromedp.Run error check and file-writing step. If the selector matches no node, the action returns an error; choose a selector present on the target page or wait for that element to appear before capturing.

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

Wait for the page’s actual ready condition

Successful navigation does not establish that every delayed image or application-rendered component is ready for capture. The screenshot examples do not promise that all asynchronous content has finished rendering when navigation returns. If a page has a known readiness condition, add an appropriate wait action before the screenshot—for example, wait for the target selector rather than relying on the navigation step alone. A fixed delay may work for one page and fail for another, so use it only when a delay is genuinely the condition you need.

Full-page capture and device emulation

FullScreenshot captures beyond the viewport, but it also overrides device emulation settings. The official example warns: “Note: chromedp.FullScreenshot overrides the device’s emulation settings. Use device.Reset to reset the emulation and viewport settings.” If you have configured emulation and need those settings restored, follow that guidance and use device.Reset as appropriate for your workflow. See the official example.

Troubleshooting

  • The screenshot action returns an error: Check the error from chromedp.Run. For element capture, confirm the CSS selector matches an element on the page; Screenshot errors when it cannot find one.
  • Content is missing from the image: Navigation alone does not guarantee that delayed images or app-rendered content is ready. Wait for a page-specific selector or other appropriate readiness condition before capture.
  • The full-page result differs from the emulated viewport: FullScreenshot overrides device emulation settings. Reset them with device.Reset when needed.
  • The file cannot be written: Check the error returned by os.WriteFile, verify the destination is writable, and ensure the filename extension reflects the selected image format.
  • The image format is unexpected: For FullScreenshot, quality 100 selects PNG; other valid quality values select JPEG. Name the output file accordingly.

Protocol options for specialized captures

The high-level helpers cover viewport, element, and full-page captures. If they do not fit a specialized need, the Chrome DevTools Protocol’s Page screenshot options include format, quality, clipping, capture from surface, capture beyond the viewport, and speed optimization. The generated bindings document PNG as the default format and capture-beyond-viewport as off by default. See the Page protocol bindings for the lower-level options; their availability and behavior should be checked against the protocol version used by your project.

Or skip the browser setup

If you need a screenshot without managing a Go browser workflow, ScreenshotNeo provides a one-request API. The following cURL example saves a WebP screenshot of https://example.com. See the ScreenshotNeo API documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

ScreenshotNeo accepts cookie and consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers indicate the page verdict and whether the request was billed. Its MCP server gives AI agents tools for screenshots, page information, and PDF capture. The free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. Learn more at ScreenshotNeo, or sign up for 1,000 free screenshots a month with no card.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Frequently Asked Questions

Can chromedp take a screenshot of an element selected by CSS?

Yes. Use `chromedp.Screenshot(selector, &buf)`; it captures the first matching element and returns an error if none matches.

Does `chromedp.FullScreenshot` save a PNG at every quality setting?

No. It selects PNG at quality 100 and JPEG for other valid quality values.

Where can I find the underlying Chrome screenshot options?

The chromedp Page bindings document protocol-level options such as clipping and capture beyond the viewport: https://github.com/chromedp/cdproto/blob/master/page/page.go.

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

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.

Leave a Reply

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

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.

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

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.