Use chromedp.Navigate to load the page, choose a screenshot action for the viewport, a visible element, or the full page, then write the returned []byte with os.WriteFile. The browser capture and the file write are separate steps, so check both errors.
Complete Go example: capture and save a full-page PNG
This standalone program starts Chromium through chromedp, navigates to a URL, captures the page beyond the viewport, and saves the PNG in the current working directory. It uses FullScreenshot with quality 100, which selects PNG encoding.
As an Amazon Associate I earn from qualifying purchases.
package main
import (
"context"
"log"
"os"
"github.com/chromedp/chromedp"
)
func main() {
ctx, cancel := chromedp.NewContext(context.Background())
defer cancel()
var screenshot []byte
if err := chromedp.Run(ctx,
chromedp.Navigate("https://example.com"),
chromedp.FullScreenshot(&screenshot, 100),
); err != nil {
log.Fatalf("capture page: %v", err)
}
if err := os.WriteFile("screenshot.png", screenshot, 0o644); err != nil {
log.Fatalf("write screenshot: %v", err)
}
}
Install chromedp in your Go module with go get github.com/chromedp/chromedp, then run the program with go run .. The output path is relative to the process’s current working directory; replace it with an absolute path if you need a predictable destination. Check the API against the chromedp version pinned in your module, because the project source and API may evolve.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Choose the capture area and image format
Capture one visible element
Use chromedp.Screenshot when you only need a selected DOM node. The selector must match an element that is visible to the browser. The following variation saves that element as PNG:
#1 Best Overall
- 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
var screenshot []byte
err := chromedp.Run(ctx,
chromedp.Navigate("https://example.com"),
chromedp.Screenshot("main article", &screenshot, chromedp.NodeVisible),
)
if err != nil {
return err
}
if err := os.WriteFile("article.png", screenshot, 0o644); err != nil {
return err
}
Place this logic inside a function that returns an error, or adapt the error handling to your program. Selectors depend on the target site’s current markup; a live site’s HTML can change, so do not treat a third-party selector as a stable fixture.
Capture only the current viewport
Use chromedp.CaptureScreenshot for the visible browser viewport rather than the whole document:
var screenshot []byte
err := chromedp.Run(ctx,
chromedp.Navigate("https://example.com"),
chromedp.CaptureScreenshot(&screenshot),
)
if err != nil {
return err
}
if err := os.WriteFile("viewport.png", screenshot, 0o644); err != nil {
return err
}
Capture beyond the viewport
chromedp.FullScreenshot is the full-size capture option. Its quality argument controls encoding: 100 produces PNG; any other value from 0 through 99 produces JPEG. Match the file extension to the actual format—for example, use 90 with full-page.jpg, not a PNG extension.
Rank #2
- 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
Wait for a page that is ready to capture
Navigate loads the URL, but some pages render important content later through JavaScript. If you know a reliable selector for the content, add a wait action before the screenshot:
err := chromedp.Run(ctx,
chromedp.Navigate("https://example.com"),
chromedp.WaitVisible("main article", chromedp.ByQuery),
chromedp.FullScreenshot(&screenshot, 100),
)
Choose a selector that indicates the content you actually need, not merely a generic page container that appears before rendering finishes. If the target does not expose a dependable selector, your application can use its own timeout or readiness condition; avoid relying on an arbitrary delay when a meaningful page signal is available.
How the save-to-file step works
The screenshot actions place encoded image bytes in the slice passed to them. They do not write a file. After chromedp.Run succeeds, call os.WriteFile(path, screenshot, 0o644) and handle its error as well. The mode is used when creating a new file; it does not override filesystem permissions or access controls.
Rank #3
- 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.
- Use a distinct filename if a repeated run should not overwrite an earlier capture.
- For batch jobs, create the destination directory before writing and include the URL or job identifier in filenames safely rather than using raw untrusted input as a path.
- Do not write the buffer after a failed browser action: capture errors can leave it empty or incomplete.
Device emulation and full-page captures
The chromedp maintainers’ screenshot example warns: “Note: chromedp.FullScreenshot overrides the device’s emulation settings. Use device.Reset to reset the emulation and viewport settings.” If your workflow configured a device viewport and will continue using the same context afterward, reset the emulation settings as needed. If the capture depends on a particular emulated viewport, verify the resulting dimensions rather than assuming the full-page action preserves that configuration.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesTroubleshooting
The file is missing or empty
- Check the error returned by
chromedp.Runbefore writing the slice. - Check the error from
os.WriteFile; the working directory may differ from the directory you expected, or the destination may not be writable. - Log the absolute output path during debugging so you can locate the file produced by a relative path.
The selector screenshot fails
Confirm that the selector matches the current page and identifies a visible node. A site redesign or delayed rendering can invalidate a previously working selector. Wait for a content-specific selector when the page renders asynchronously.
The screenshot has the wrong format
For FullScreenshot, use quality 100 and a .png filename for PNG, or a quality from 0 to 99 and a .jpg or .jpeg filename for JPEG. The file extension does not convert the bytes.
Rank #4
- 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
There is no browser window
chromedp runs Chrome headlessly by default, so a visible browser window is not required for capture. The screenshot is still produced as bytes by the browser automation.
The run ends with a canceled context
A canceled context can result when the browser connection is lost or the context is canceled elsewhere. Keep the context alive through navigation, capture, and file writing; inspect the original error and browser lifecycle before retrying.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Performance, reliability, and cost considerations
Capture time depends on browser startup, page loading, rendering, and image size; the cited chromedp APIs do not establish a general performance figure. Reuse browser infrastructure where appropriate for a high-volume worker, but give each job clear context cancellation and error handling. Full-page images can be substantially larger than viewport or element captures, so choose the smallest capture scope that meets the job’s need. No fixed chromedp release version or universal runtime is specified here; check the version in your Go module and the target site’s behavior.
Best Value
- 【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.
Or skip the browser setup
ScreenshotNeo provides a screenshot API if you would rather not manage Chromium in your Go application. One GET request returns an image or PDF. The service accepts cookie and consent banners before capture 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 are not billed, and response headers report the page verdict and billing status.
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. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.
Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month without a card.
Recommended Free Tools
Frequently Asked Questions
Does chromedp save the screenshot file automatically?
No. The capture action returns encoded bytes to your Go slice; write them separately with a filesystem function such as os.WriteFile.
Which chromedp screenshot method captures the full page?
Use chromedp.FullScreenshot for a capture beyond the current viewport.
Quick Recap
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.




