Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk4 min

How to Screenshot an HTML Page with Go and Headless Chrome in Docker

A practical Go and chromedp guide to capturing HTML pages with headless Chrome in Docker, saving screenshot bytes, choosing capture scope, and resolving common container failures.

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.

Use chromedp to drive Chrome through the Chrome DevTools Protocol (CDP), capture the page as image bytes, and write those bytes to a file. For a practical container starting point, run the Go program with the chromedp project’s docker.io/chromedp/headless-shell image. The example below captures a full page; choose a different chromedp action if you need one visible element or only the current viewport.

Choose the capture type before writing the code

A screenshot action determines what part of the rendered page you receive. These are not interchangeable:

As an Amazon Associate I earn from qualifying purchases.

Capture Chromedp action Use it for
One visible element chromedp.Screenshot(selector, &buf, chromedp.NodeVisible) A matching visible node, such as a chart or card.
Current viewport chromedp.CaptureScreenshot(&buf) The browser’s current view, rather than content below the fold.
Full page chromedp.FullScreenshot(&buf, quality) A capture of the whole page. The API accepts quality from 0 to 100; quality 100 produces PNG, while lower values produce JPEG.

FullScreenshot overrides device-emulation settings. If your workflow sets emulation or viewport dimensions, do not assume those settings remain in effect for a full-page capture; review chromedp’s device-setting behavior for your chosen flow.

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

Build a Go screenshot program

This runnable-shaped example navigates to a URL, captures the full page as PNG bytes, and writes page.png. It is based on the upstream chromedp API and screenshot example; the code has not been executed as part of this article, so validate it against the Go and browser versions you deploy.

#1 Best Overall
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
  • Includes Raspberry Pi 5 with 2.4Ghz 64-bit quad-core CPU (8GB RAM)
  • Includes 128GB Micro SD Card pre-loaded with 64-bit Raspberry Pi OS, USB MicroSD Card Reader
  • CanaKit Turbine Black Case for the Raspberry Pi 5
  • CanaKit Low Noise Bearing System Fan
  • Mega Heat Sink - Black Anodized
package main

import (
	"context"
	"fmt"
	"os"

	"github.com/chromedp/chromedp"
)

func main() {
	url := "https://example.com"
	ctx, cancel := chromedp.NewContext(context.Background())
	defer cancel()

	var buf []byte
	if err := chromedp.Run(ctx,
		chromedp.Navigate(url),
		chromedp.FullScreenshot(&buf, 100),
	); err != nil {
			fmt.Fprintln(os.Stderr, "capture failed:", err)
			os.Exit(1)
	}

	if err := os.WriteFile("page.png", buf, 0o644); err != nil {
		fmt.Fprintln(os.Stderr, "write screenshot:", err)
		os.Exit(1)
	}
}

Initialize the module and fetch the dependency with Go’s module tooling, then build the program for the environment in which it will run. Add application-specific URL validation and error handling before accepting URLs from users. For an element capture, replace the full-page action with a selector action, for example chromedp.Screenshot("#report", &buf, chromedp.NodeVisible). For the viewport, use chromedp.CaptureScreenshot(&buf).

Run Chrome in Docker

chromedp is the Go control layer; Chrome or headless-shell is still the browser runtime. The chromedp project describes docker.io/chromedp/headless-shell as a multi-architecture image made for chromedp, and the package documentation identifies it as a straightforward headless-environment path. Follow the image README’s documented invocation and publish port 9222 when the Go process must connect to its debugging endpoint. Keep that endpoint reachable only to the Go process that needs it; broad exposure of remote debugging is not a safe default.

Rank #2
CanaKit Raspberry Pi 5 16GB Starter Kit PRO - Turbine Black (128GB Edition) (16GB RAM)
  • Includes Raspberry Pi 5 16GB with 2.4Ghz 64-bit quad-core CPU (16GB RAM)
  • Includes 128GB Micro SD Card pre-loaded with 64-bit Raspberry Pi OS, USB MicroSD Card Reader
  • CanaKit Turbine Black Case for the Raspberry Pi 5
  • CanaKit Low Noise Bearing System Fan
  • Mega Heat Sink - Black Anodized

Image tag choice

The image README documents floating stable, beta, and dev channel tags as well as specific version tags. Channel images are pushed daily, so a floating tag can move as the channel updates. Pin a specific version tag when you need the browser version to be explicit and deployments to be reproducible; check the project’s README for currently available tags because version availability changes.

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

Browser lifecycle choices

By default, chromedp creates a context and launches a browser for the task workflow. If Chrome is instead a separately managed, long-running process, chromedp documents RemoteAllocator for connecting to it. In that arrangement, the application depends on the remote browser remaining available for the duration of navigation and capture. A lost browser connection cancels the chromedp context; check errors returned by chromedp.Run rather than assuming a screenshot was produced.

Rank #3
CanaKit Raspberry Pi 5 Essentials Starter Kit (4GB RAM)
  • CanaKit Raspberry Pi 5 Essentials Starter Kit

For a short-lived browser started by the Go program, keep the context alive through capture and file writing, and cancel it when finished. On Linux, chromedp force-kills Chrome child processes it started when the Go program exits. The browser lifecycle differs when connecting to an independently managed process, so manage that service separately.

Handle common Docker and capture failures

  • Container exits with BUS_ADRERR: the headless-shell README recommends trying a larger shared-memory allocation, such as Docker’s --shm-size 2G. Treat this as a conditional fix for that failure, not a universal requirement.
  • Zombie processes appear: the image README warns this can happen when using the image directly or as a base image. It recommends Docker’s --init argument so an init process can reap child processes.
  • chromedp.Run returns an error: inspect whether navigation or capture failed, and whether the browser connection was closed or killed. Chromedp cancels its context when the browser connection is lost.
  • The output is empty or not the intended image: confirm that navigation and the screenshot action both completed without error, that the selected CSS element exists and is visible when using selector capture, and that the program writes the returned byte buffer.
  • Viewport or device emulation differs in a full-page capture: FullScreenshot overrides device-emulation settings. Use a capture action suited to the intended extent and account for that override rather than relying on previously configured emulation.

Or skip the browser setup

ScreenshotNeo provides a website screenshot API and MCP server. One GET request returns an image or PDF, without requiring you to run a browser container for the capture.

Rank #4
SANOOV Raspberry Pi 5 4GB Kit, 4GB RAM Single Board Computer with Active Cooler and ABS Case, Complete Raspberry Pi 5 Starter Kit for IoT Robotics Retro Gaming
  • All-in-One Complete Kit: This SANOOV RPi 5 bundle comes with Raspberry Pi 5 4GB RAM single board, active cooler, durable ABS case and screwdriver. No extra parts needed, ready to use right out of the box for beginners and hobbyists
  • Powerful Single Board Computer: Equipped with 4GB RAM and high-performance processor, delivers fast running speed for 4K playback, AI projects, programming and daily computing tasks. SANOOV for raspberry pi 5 4GB is equipped with broadcom 64 quad-core Arm Cortex A76 processor with gigabit ethernet and upgraded with IEEE 802.11ac Wi-Fi, Bluetooth 5.0 dual-band 2.4Ghz and 5Ghz and Power Over Ethernet (POE). Upgrading delivers 2-3 x speed vs Pi 4, redefining the experience
  • Efficient Active Cooler: Effectively lowers operating temperature and prevents performance throttling. Runs quietly even under long-time heavy load, ensures stable operation all day long. SANOOV RPi 5 4GB kit offer an active cooler, which combines an aluminium heatsink with a high-performance PWM fan. Active cooler is fully compatible with the Pi OS, which can effectively reduce the temperature of RPi5 and ensure its good performance during long-term high load operation
  • Sturdy ABS Protective Case: Well-fitted for Raspberry Pi 5 board, can be secured with 4 screws to effectively protect the Pi 5 motherboard from damage, reserves full access to all ports and buttons. SANOOV uses ABS material to produce the case, which has a softer texture and feel. Meanwhile, SANOOV case adopts a layered design for easy disassembly and installation. (Tip: The Case cannot install M.2 HAT Add on Board and Solid State Drive!)
  • Wide Application & Full Compatibility: Seamlessly compatible with official OS and mainstream peripheral accessories for Raspberry Pi 5. Whether you are a beginner, student, electronics hobbyist or professional developer, this all-in-one kit meets your diverse needs. It excels in IoT projects, robotics design, retro gaming devices, home media servers and other DIY creations. Backed by a large global community, you can easily find guides, technical support and shared projects online
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 API documentation for request options. Cookie and consent banners, newsletter popups, and chat widgets are removed before capture; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. Its MCP server gives AI agents screenshot tools. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots.

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

Sign up for ScreenshotNeo’s free plan to get 1,000 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

Does chromedp itself render the page?

No. Chromedp controls Chrome through CDP; Chrome or headless-shell performs the rendering.

Best Value
RasTech Raspberry Pi 5 8GB Kit with Active Cooler and Pi5 Case
  • 【What you Get】You will get 1*Pi 5 8GB Single Board,1*RasTech Case,1*Active Cooler,1*Screwdriver,1*Installation instructions,12-month free warranty, lifetime service, 24-hour prompt and friendly response.
  • 【More Connectors】There are two USB 3.0 ports(5Gbps simultaneously) and two USB 2.0 ports, which triple total bandwidth ,support any combination of up to two cameras or displays. Peak SD card performance is doubled through support for the SDR104 high-speed mode. It provides a smooth desktop experience for you. Offer Gigabit Ethernet and a PCIe interface, along with dual-band Wi-Fi and Bluetooth 5.0/BLE wireless capability. The RasTech Pi 5 Kit use the new 27W 5.1V 5A USB-C power connector.
  • 【 Support Dual 4Kp60 Display 】Each of the two microHDMI sockets can control a 4K display at 60 Hertz, now support HDR, offering super HD video for media streaming projects. RPi 5 is the first RPi model that comes with a PCI Express port (PCIe 2.0 x1 with 500 MB/s) to attach SSDs (requires separate M.2 HAT).
  • 【 Excellent Chips And Applications】Pi 5 is a full-size Pi computer using silicon built in-house at Pi. The RP1 “southbridge” provides the bulk of the I/O capabilities for Pi 5. Pi 5 is more friendly and convenient in the development of Internet of Things, Web development, machine identification, automatic control and other electronic equipment applications and network.
  • 【 Faster CPU, Better GPU 】 Pi 5 features a Broadcom BCM2712 64-bit quad-core Arm Cortex-A76 processor running at 2.4GHz, it delivers a 2–3× increase in CPU performance relative to RaspberryPi 4. The 800MHz VideoCore VII GPU is compatible to OpenGL ES 3.1 and Vulkan 1.2, substantial uplift in graphics performance. Pi 5 Offers lightning-fast CPU speed, a PCI Express interface, a Real Time Clock (RTC) and a power button and runs significantly cooler than Pi 4.

Can I save a JPEG instead of a PNG?

With FullScreenshot, the chromedp API documents quality 100 as PNG and lower quality values as JPEG.

Quick Recap

Bestseller No. 1
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
Includes Raspberry Pi 5 with 2.4Ghz 64-bit quad-core CPU (8GB RAM); CanaKit Turbine Black Case for the Raspberry Pi 5
$259.95
Bestseller No. 2
CanaKit Raspberry Pi 5 16GB Starter Kit PRO - Turbine Black (128GB Edition) (16GB RAM)
CanaKit Raspberry Pi 5 16GB Starter Kit PRO - Turbine Black (128GB Edition) (16GB RAM)
Includes Raspberry Pi 5 16GB with 2.4Ghz 64-bit quad-core CPU (16GB RAM); CanaKit Turbine Black Case for the Raspberry Pi 5
$419.99
Bestseller No. 3
CanaKit Raspberry Pi 5 Essentials Starter Kit (4GB RAM)
CanaKit Raspberry Pi 5 Essentials Starter Kit (4GB RAM)
CanaKit Raspberry Pi 5 Essentials Starter Kit
$189.99

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 *

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
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.