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
Chrome automation

How to Capture a Full Web Page in Go (PNG, JPEG, or PDF)

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

To capture everything below the fold in Go, render the URL in a real Chrome or Chromium browser, wait until the page’s own content is ready, then use a full-page API. The shortest path is chromedp and chromedp.FullScreenshot; Rod offers the equivalent Page.Screenshot(true, ...). A normal viewport screenshot captures only what is visible, while full-page mode captures the document’s complete scrollable content.

What “full page” means

A viewport capture is limited to the browser window. A full-page capture includes content below the fold by measuring or rendering the page’s scrollable document before taking the image. Playwright describes the target as the “Full scrollable page instead of the viewport” (documentation).

Go does not draw webpages itself. Your program must control a browser runtime, normally Chrome or Chromium, through the Chrome DevTools Protocol. The browser executes JavaScript, applies CSS, loads fonts and images, and produces the pixels that the screenshot API returns.

Prerequisites and project setup

  • Go installed and a module created with go mod init.
  • A Chrome or Chromium executable available on the development or deployment machine.
  • A URL that the browser can reach, plus any authentication, cookies or headers it needs.
  • A readiness condition for dynamic content; navigation completing does not always mean an application has finished rendering.

For chromedp, add the dependency with:

go get github.com/chromedp/chromedp

In containers or CI, install a compatible Chrome/Chromium package and ensure the process user can launch it. Browser startup and lifecycle management are deployment concerns, not screenshot-format settings.

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

Recommended method: chromedp full-page PNG

chromedp exposes an API named for this job: FullScreenshot. Its package documentation says it takes a full screenshot of the entire browser viewport at the specified image quality. Quality 100 produces PNG; lower values produce JPEG.

Complete runnable program

package main

import (
    "context"
    "fmt"
    "os"
    "time"

    "github.com/chromedp/chromedp"
)

func main() {
    if len(os.Args) != 2 {
        fmt.Fprintf(os.Stderr, "usage: %s https://example.comn", os.Args[0])
        os.Exit(2)
    }
    url := os.Args[1]

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

    // Bound navigation, rendering and capture so a broken page cannot hang forever.
    ctx, cancel = context.WithTimeout(ctx, 90*time.Second)
    defer cancel()

    var buf []byte
    err := chromedp.Run(ctx,
        chromedp.Navigate(url),
        // Add site-specific waits here (see the next section).
        chromedp.FullScreenshot(&buf, 100), // PNG
    )
    if err != nil {
        fmt.Fprintf(os.Stderr, "capture failed: %vn", err)
        os.Exit(1)
    }
    if err := os.WriteFile("page.png", buf, 0o644); err != nil {
        fmt.Fprintf(os.Stderr, "write failed: %vn", err)
        os.Exit(1)
    }
}

Run it with go run . https://example.com. The bytes returned by FullScreenshot are the encoded image; write them directly rather than converting through a second image library.

Waiting for the page’s real readiness state

Full-page capture records whatever Chrome has rendered at that instant. For a server-rendered document, navigation may be sufficient. Single-page applications, lazy images, web fonts, consent dialogs and animations need an explicit condition. Examples include:

chromedp.Navigate(url),
chromedp.WaitVisible(`#report`, chromedp.ByID),
chromedp.WaitReady(`main`, chromedp.ByQuery),
chromedp.FullScreenshot(&buf, 100),

You can also run JavaScript that waits for an application flag, or insert a deliberate delay when no reliable selector exists. A delay is a fallback, not a universal guarantee: network speed and application data can vary. For lazy-loaded content, scroll the page (or trigger the site’s load mechanism) before the final capture, then wait for the last image or data selector.

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.

JPEG output

Pass a value below 100 to request JPEG compression:

chromedp.FullScreenshot(&buf, 90)

JPEG is smaller for photographic pages but lossy. Use PNG for text, diagrams, pixel comparisons and transparent-looking UI edges; use JPEG when storage or transfer size matters more than exact pixels.

Rod alternative: an explicit full-page switch

Rod’s Page.Screenshot method takes a boolean full-page argument. With true, Rod measures CSS content size and adjusts the viewport before capture, which is useful when the document is taller than the current viewport.

package main

import (
    "os"

    "github.com/go-rod/rod"
    "github.com/go-rod/rod/lib/proto"
)

func main() {
    browser := rod.New().MustConnect()
    defer browser.MustClose()

    page := browser.MustPage("https://example.com")
    // Add waits such as page.MustWaitLoad() or a selector-specific wait as needed.
    img, err := page.Screenshot(true, &proto.PageCaptureScreenshot{})
    if err != nil {
        panic(err)
    }
    if err := os.WriteFile("page.png", img, 0o644); err != nil {
        panic(err)
    }
}

Choose chromedp when you want a small action pipeline and a function explicitly named FullScreenshot. Choose Rod when its fluent API, page lifecycle controls or full-page boolean fit your codebase. Neither library removes the need to supply Chrome and define when the page is ready.

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.

Controlling browser state for accurate captures

Viewport, device scale and responsive layout

Responsive sites can produce radically different pages at different viewport widths. Set the emulated viewport before navigation when a specific desktop, tablet or mobile layout is required. Device scale affects pixel dimensions and sharpness; record your chosen width, height and scale so repeated captures are comparable.

Authentication, cookies and headers

Private pages need a logged-in browser context, session cookies or request headers before navigation. Do not put credentials in a public URL or commit them to source control. For deterministic jobs, create an isolated browser context, inject only the required cookies or headers, and close it after capture.

Consent banners, overlays and animation

A cookie dialog, newsletter modal or chat widget can obscure the page even when the document is fully captured. Automate the consent action when legally and technically appropriate, or hide the overlay with page-specific CSS before the screenshot. Disable or freeze animations if visual comparisons matter; otherwise a capture can differ from run to run.

Infinite scroll and very large documents

“Full page” has a finite meaning for an infinite feed. Decide on a stopping rule—item count, maximum height or a “load more” action—then capture the resulting bounded document. Extremely tall pages consume browser memory and may exceed image-dimension limits; split them into sections or produce a PDF when a single raster is impractical.

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

PDF instead of an image

A PDF is a print-layout operation rather than a raster screenshot. Use Chrome DevTools Protocol’s print-to-PDF support through your Go library when selectable text, pagination and paper size matter. Define paper format, margins, landscape orientation and page ranges for repeatable output. A PDF can paginate content that would be one exceptionally tall PNG; it will not necessarily match a full-page image’s pixels or background behavior.

Reliability, concurrency and cost considerations

  • Bound every job. Apply a context timeout and return a useful error when navigation, a selector wait or capture exceeds it.
  • Reuse browsers carefully. Keeping one browser process and creating isolated pages reduces startup overhead, but cap concurrent pages to avoid CPU and memory contention.
  • Clean up. Cancel contexts and close pages or browsers on success and failure, including when a write operation fails.
  • Make outputs atomic. Write to a temporary file and rename it, so readers never observe a partially written image.
  • Log the cause. Record URL, viewport, browser version, wait condition and elapsed stages. The primary documentation provides no universal latency, fidelity or failure-rate benchmark, so measure your own workload rather than publishing a guessed number.

Troubleshooting common failures

Only the visible viewport was captured

Check that you called chromedp’s FullScreenshot, not a viewport-only screenshot command, and that Rod’s first argument is true. Confirm the page itself has finished adding content before capture.

Images or fonts are missing

Wait for a specific image, component or font-ready condition. Verify that the browser can reach the asset host and that authentication, CSP or blocked requests are not preventing loading. For lazy images, trigger the site’s loading behavior before taking the screenshot.

The output is blank or navigation times out

Open the same URL in the supplied Chrome runtime, check DNS and TLS access, and inspect console or network errors. Increase the timeout only after ruling out an unreachable host or a page that intentionally waits for user interaction.

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

Chrome cannot start in CI or a container

Install a compatible Chrome/Chromium binary, pass the executable path if it is not discoverable, and configure the sandbox according to your platform’s security policy. Ensure the runtime user has permission to launch the binary and write the destination file.

Capture differs between runs

Fix viewport and device scale, wait for fonts and data, freeze animations, use a stable test account, and avoid time-dependent content. Full-page measurement can change when late-loading elements alter document height, so capture only after the final layout condition is true.

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

Or skip the browser setup

ScreenshotNeo provides a website screenshot API and MCP server when you do not want to maintain Chrome automation. One GET request returns PNG, JPEG, WebP or PDF. It accepts cookie or consent banners before capture and removes more than 60 known consent platforms, newsletter popups and chat widgets; each step can be disabled. Only clean shots are billed: bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits cost nothing, and response headers identify the page verdict and billing status.

Using Go’s HTTP client:

package main

import (
    "os"
    "github.com/screenshotneo/example"
)

func main() {
    // See the complete parameter list and response handling in the
    // ScreenshotNeo documentation: https://screenshotneo.com/docs/
    _ = os.Stdout
}

Use the API directly from any Go HTTP client (the endpoint and parameters are documented at https://screenshotneo.com/docs/):

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://stripe.com -o shot.webp

ScreenshotNeo also supports full-page capture with lazy images loaded, CSS-element capture, device presets or custom viewports, retina scale, custom CSS and JavaScript, clicks, selector or network-idle waits, request blocking, headers, cookies, user agents, authorization, timezone and geolocation, transparent backgrounds, resizing, configurable caching, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API and an OpenAPI specification. Its MCP server exposes take_screenshot, get_page_info and capture_pdf to Claude, Cursor and other MCP clients.

There is a free allowance of 1,000 screenshots each month with no card. Paid plans start at $5 for 3,000 shots; every feature is on every plan. Create a free ScreenshotNeo account to try the API.

FAQ

Does full-page capture automatically load every lazy image?

No. It captures the rendered state at capture time. Trigger the site’s lazy-loading behavior and wait for the resulting elements before calling the screenshot method.

Can I capture a page without installing Chrome?

Local chromedp and Rod workflows require a Chrome/Chromium runtime. A hosted API such as ScreenshotNeo removes that browser-binary maintenance.

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

Which format should I archive?

Use PNG for lossless pixels and visual testing, JPEG for smaller photographic images, and PDF when pagination and selectable text are the primary requirements.

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 *

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

Read next

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