Back to articles
How to Take Screenshots in Go with the PageBolt API

How to Take Screenshots in Go with the PageBolt API

via Dev.to WebdevCustodia-Admin

How to Take Screenshots in Go with the PageBolt API You're building a Go service that needs screenshots. You reach for json.Unmarshal and... nothing happens. The response is binary PNG data, not JSON. This is the most common mistake when integrating screenshot APIs in Go. Here's the right way: treat the response as raw bytes, not JSON. The Basic Pattern: Binary Response Handling package main import ( "bytes" "encoding/json" "fmt" "io" "net/http" "os" ) // ScreenshotRequest defines the request payload type ScreenshotRequest struct { URL string `json:"url"` Format string `json:"format"` // png, jpeg, webp Width int `json:"width,omitempty"` Height int `json:"height,omitempty"` FullPage bool `json:"fullPage,omitempty"` BlockBanners bool `json:"blockBanners,omitempty"` } func takeScreenshot ( url , outputPath , apiKey string ) error { // Build request reqBody := ScreenshotRequest { URL : url , Format : "png" , Width : 1280 , Height : 720 , FullPage : true , BlockBanners : true , } // Marsha

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
7 views

Related Articles