Skip to content
Start here

Get screenshot.

client.BrowserRendering.Screenshot.New(ctx, params) (*ScreenshotNewResponse, error)
POST/accounts/{account_id}/browser-rendering/screenshot

Takes a screenshot of a webpage from provided URL or HTML. Control page loading with gotoOptions and waitFor* options. Customize screenshots with viewport, fullPage, clip and others.

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
Accepted Permissions (at least one required)
Browser Rendering Write
ParametersExpand Collapse
params ScreenshotNewParams
AccountID param.Field[string]

Path param: Account ID.

HTML param.Field[string]

Body param: Set the content of the page, eg: <h1>Hello World!!</h1>. Either html or url must be set.

minLength1
CacheTTL param.Field[float64]optional

Query param: Cache TTL default is 5s. Set to 0 to disable.

maximum86400
ActionTimeout param.Field[float64]optional

Body param: The maximum duration allowed for the browser action to complete after the page has loaded (such as taking screenshots, extracting content, or generating PDFs). If this time limit is exceeded, the action stops and returns a timeout error.

maximum120000
AddScriptTag param.Field[[]ScreenshotNewParamsVariant0AddScriptTag]optional

Body param: Adds a <script> tag into the page with the desired URL or content.

ID stringoptional
Content stringoptional
Type stringoptional
URL stringoptional
AddStyleTag param.Field[[]ScreenshotNewParamsVariant0AddStyleTag]optional

Body param: Adds a <link rel="stylesheet"> tag into the page with the desired URL or a <style type="text/css"> tag with the content.

Content stringoptional
URL stringoptional
AllowRequestPattern param.Field[[]string]optional

Body param: Only allow requests that match the provided regex patterns, eg. '/^.*.(css)'.

AllowResourceTypes param.Field[[]ScreenshotNewParamsVariant0AllowResourceType]optional

Body param: Only allow requests that match the provided resource types, eg. 'image' or 'script'.

const ScreenshotNewParamsVariant0AllowResourceTypeDocument ScreenshotNewParamsVariant0AllowResourceType = "document"
const ScreenshotNewParamsVariant0AllowResourceTypeStylesheet ScreenshotNewParamsVariant0AllowResourceType = "stylesheet"
const ScreenshotNewParamsVariant0AllowResourceTypeImage ScreenshotNewParamsVariant0AllowResourceType = "image"
const ScreenshotNewParamsVariant0AllowResourceTypeMedia ScreenshotNewParamsVariant0AllowResourceType = "media"
const ScreenshotNewParamsVariant0AllowResourceTypeFont ScreenshotNewParamsVariant0AllowResourceType = "font"
const ScreenshotNewParamsVariant0AllowResourceTypeScript ScreenshotNewParamsVariant0AllowResourceType = "script"
const ScreenshotNewParamsVariant0AllowResourceTypeTexttrack ScreenshotNewParamsVariant0AllowResourceType = "texttrack"
const ScreenshotNewParamsVariant0AllowResourceTypeXHR ScreenshotNewParamsVariant0AllowResourceType = "xhr"
const ScreenshotNewParamsVariant0AllowResourceTypeFetch ScreenshotNewParamsVariant0AllowResourceType = "fetch"
const ScreenshotNewParamsVariant0AllowResourceTypePrefetch ScreenshotNewParamsVariant0AllowResourceType = "prefetch"
const ScreenshotNewParamsVariant0AllowResourceTypeEventsource ScreenshotNewParamsVariant0AllowResourceType = "eventsource"
const ScreenshotNewParamsVariant0AllowResourceTypeWebsocket ScreenshotNewParamsVariant0AllowResourceType = "websocket"
const ScreenshotNewParamsVariant0AllowResourceTypeManifest ScreenshotNewParamsVariant0AllowResourceType = "manifest"
const ScreenshotNewParamsVariant0AllowResourceTypeSignedexchange ScreenshotNewParamsVariant0AllowResourceType = "signedexchange"
const ScreenshotNewParamsVariant0AllowResourceTypePing ScreenshotNewParamsVariant0AllowResourceType = "ping"
const ScreenshotNewParamsVariant0AllowResourceTypeCspviolationreport ScreenshotNewParamsVariant0AllowResourceType = "cspviolationreport"
const ScreenshotNewParamsVariant0AllowResourceTypePreflight ScreenshotNewParamsVariant0AllowResourceType = "preflight"
const ScreenshotNewParamsVariant0AllowResourceTypeOther ScreenshotNewParamsVariant0AllowResourceType = "other"
Authenticate param.Field[ScreenshotNewParamsVariant0Authenticate]optional

Body param: Provide credentials for HTTP authentication.

Password string
minLength1
Username string
minLength1
BestAttempt param.Field[bool]optional

Body param: Attempt to proceed when 'awaited' events fail or timeout.

Cookies param.Field[[]ScreenshotNewParamsVariant0Cookie]optional

Body param: Check options.

Name string

Cookie name.

Value string
Domain stringoptional
Expires float64optional
HTTPOnly booloptional
PartitionKey stringoptional
Path stringoptional
Priority ScreenshotNewParamsVariant0CookiesPriorityoptional
One of the following:
const ScreenshotNewParamsVariant0CookiesPriorityLow ScreenshotNewParamsVariant0CookiesPriority = "Low"
const ScreenshotNewParamsVariant0CookiesPriorityMedium ScreenshotNewParamsVariant0CookiesPriority = "Medium"
const ScreenshotNewParamsVariant0CookiesPriorityHigh ScreenshotNewParamsVariant0CookiesPriority = "High"
SameParty booloptional
SameSite ScreenshotNewParamsVariant0CookiesSameSiteoptional
One of the following:
const ScreenshotNewParamsVariant0CookiesSameSiteStrict ScreenshotNewParamsVariant0CookiesSameSite = "Strict"
const ScreenshotNewParamsVariant0CookiesSameSiteLax ScreenshotNewParamsVariant0CookiesSameSite = "Lax"
const ScreenshotNewParamsVariant0CookiesSameSiteNone ScreenshotNewParamsVariant0CookiesSameSite = "None"
Secure booloptional
SourcePort float64optional
SourceScheme ScreenshotNewParamsVariant0CookiesSourceSchemeoptional
One of the following:
const ScreenshotNewParamsVariant0CookiesSourceSchemeUnset ScreenshotNewParamsVariant0CookiesSourceScheme = "Unset"
const ScreenshotNewParamsVariant0CookiesSourceSchemeNonSecure ScreenshotNewParamsVariant0CookiesSourceScheme = "NonSecure"
const ScreenshotNewParamsVariant0CookiesSourceSchemeSecure ScreenshotNewParamsVariant0CookiesSourceScheme = "Secure"
URL stringoptional
EmulateMediaType param.Field[string]optional

Body param

GotoOptions param.Field[ScreenshotNewParamsVariant0GotoOptions]optional

Body param: Check options.

Referer stringoptional
ReferrerPolicy stringoptional
Timeout float64optional
maximum60000
WaitUntil ScreenshotNewParamsVariant0GotoOptionsWaitUntilUnionoptional
One of the following:
ScreenshotNewParamsVariant0GotoOptionsWaitUntilString
One of the following:
const ScreenshotNewParamsVariant0GotoOptionsWaitUntilStringLoad ScreenshotNewParamsVariant0GotoOptionsWaitUntilString = "load"
const ScreenshotNewParamsVariant0GotoOptionsWaitUntilStringDomcontentloaded ScreenshotNewParamsVariant0GotoOptionsWaitUntilString = "domcontentloaded"
const ScreenshotNewParamsVariant0GotoOptionsWaitUntilStringNetworkidle0 ScreenshotNewParamsVariant0GotoOptionsWaitUntilString = "networkidle0"
const ScreenshotNewParamsVariant0GotoOptionsWaitUntilStringNetworkidle2 ScreenshotNewParamsVariant0GotoOptionsWaitUntilString = "networkidle2"
ScreenshotNewParamsVariant0GotoOptionsWaitUntilArray
One of the following:
const ScreenshotNewParamsVariant0GotoOptionsWaitUntilArrayLoad ScreenshotNewParamsVariant0GotoOptionsWaitUntilArray = "load"
const ScreenshotNewParamsVariant0GotoOptionsWaitUntilArrayDomcontentloaded ScreenshotNewParamsVariant0GotoOptionsWaitUntilArray = "domcontentloaded"
const ScreenshotNewParamsVariant0GotoOptionsWaitUntilArrayNetworkidle0 ScreenshotNewParamsVariant0GotoOptionsWaitUntilArray = "networkidle0"
const ScreenshotNewParamsVariant0GotoOptionsWaitUntilArrayNetworkidle2 ScreenshotNewParamsVariant0GotoOptionsWaitUntilArray = "networkidle2"
RejectRequestPattern param.Field[[]string]optional

Body param: Block undesired requests that match the provided regex patterns, eg. '/^.*.(css)'.

RejectResourceTypes param.Field[[]ScreenshotNewParamsVariant0RejectResourceType]optional

Body param: Block undesired requests that match the provided resource types, eg. 'image' or 'script'.

const ScreenshotNewParamsVariant0RejectResourceTypeDocument ScreenshotNewParamsVariant0RejectResourceType = "document"
const ScreenshotNewParamsVariant0RejectResourceTypeStylesheet ScreenshotNewParamsVariant0RejectResourceType = "stylesheet"
const ScreenshotNewParamsVariant0RejectResourceTypeImage ScreenshotNewParamsVariant0RejectResourceType = "image"
const ScreenshotNewParamsVariant0RejectResourceTypeMedia ScreenshotNewParamsVariant0RejectResourceType = "media"
const ScreenshotNewParamsVariant0RejectResourceTypeFont ScreenshotNewParamsVariant0RejectResourceType = "font"
const ScreenshotNewParamsVariant0RejectResourceTypeScript ScreenshotNewParamsVariant0RejectResourceType = "script"
const ScreenshotNewParamsVariant0RejectResourceTypeTexttrack ScreenshotNewParamsVariant0RejectResourceType = "texttrack"
const ScreenshotNewParamsVariant0RejectResourceTypeXHR ScreenshotNewParamsVariant0RejectResourceType = "xhr"
const ScreenshotNewParamsVariant0RejectResourceTypeFetch ScreenshotNewParamsVariant0RejectResourceType = "fetch"
const ScreenshotNewParamsVariant0RejectResourceTypePrefetch ScreenshotNewParamsVariant0RejectResourceType = "prefetch"
const ScreenshotNewParamsVariant0RejectResourceTypeEventsource ScreenshotNewParamsVariant0RejectResourceType = "eventsource"
const ScreenshotNewParamsVariant0RejectResourceTypeWebsocket ScreenshotNewParamsVariant0RejectResourceType = "websocket"
const ScreenshotNewParamsVariant0RejectResourceTypeManifest ScreenshotNewParamsVariant0RejectResourceType = "manifest"
const ScreenshotNewParamsVariant0RejectResourceTypeSignedexchange ScreenshotNewParamsVariant0RejectResourceType = "signedexchange"
const ScreenshotNewParamsVariant0RejectResourceTypePing ScreenshotNewParamsVariant0RejectResourceType = "ping"
const ScreenshotNewParamsVariant0RejectResourceTypeCspviolationreport ScreenshotNewParamsVariant0RejectResourceType = "cspviolationreport"
const ScreenshotNewParamsVariant0RejectResourceTypePreflight ScreenshotNewParamsVariant0RejectResourceType = "preflight"
const ScreenshotNewParamsVariant0RejectResourceTypeOther ScreenshotNewParamsVariant0RejectResourceType = "other"
ScreenshotOptions param.Field[ScreenshotNewParamsVariant0ScreenshotOptions]optional

Body param: Check options.

CaptureBeyondViewport booloptional
Clip ScreenshotNewParamsVariant0ScreenshotOptionsClipoptional
Height float64
Width float64
X float64
Y float64
Scale float64optional
Encoding ScreenshotNewParamsVariant0ScreenshotOptionsEncodingoptional
One of the following:
const ScreenshotNewParamsVariant0ScreenshotOptionsEncodingBinary ScreenshotNewParamsVariant0ScreenshotOptionsEncoding = "binary"
const ScreenshotNewParamsVariant0ScreenshotOptionsEncodingBase64 ScreenshotNewParamsVariant0ScreenshotOptionsEncoding = "base64"
FromSurface booloptional
FullPage booloptional
OmitBackground booloptional
OptimizeForSpeed booloptional
Quality float64optional
Type ScreenshotNewParamsVariant0ScreenshotOptionsTypeoptional
One of the following:
const ScreenshotNewParamsVariant0ScreenshotOptionsTypePNG ScreenshotNewParamsVariant0ScreenshotOptionsType = "png"
const ScreenshotNewParamsVariant0ScreenshotOptionsTypeJPEG ScreenshotNewParamsVariant0ScreenshotOptionsType = "jpeg"
const ScreenshotNewParamsVariant0ScreenshotOptionsTypeWebP ScreenshotNewParamsVariant0ScreenshotOptionsType = "webp"
ScrollPage param.Field[bool]optional

Body param

Selector param.Field[string]optional

Body param

SetExtraHTTPHeaders param.Field[map[string, string]]optional

Body param

SetJavaScriptEnabled param.Field[bool]optional

Body param

UserAgent param.Field[string]optional

Body param

Viewport param.Field[ScreenshotNewParamsVariant0Viewport]optional

Body param: Check options.

Height float64
Width float64
DeviceScaleFactor float64optional
HasTouch booloptional
IsLandscape booloptional
IsMobile booloptional
WaitForSelector param.Field[ScreenshotNewParamsVariant0WaitForSelector]optional

Body param: Wait for the selector to appear in page. Check options.

Selector string
Hidden ScreenshotNewParamsVariant0WaitForSelectorHiddenoptional
Timeout float64optional
maximum120000
Visible ScreenshotNewParamsVariant0WaitForSelectorVisibleoptional
WaitForTimeout param.Field[float64]optional

Body param: Waits for a specified timeout before continuing.

maximum120000
ReturnsExpand Collapse
type ScreenshotNewResponse struct{…}
Success bool

Response status.

Errors []ScreenshotNewResponseErroroptional
Code float64

Error code.

Message string

Error message.

Get screenshot.

package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/browser_rendering"
  "github.com/cloudflare/cloudflare-go/option"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  screenshot, err := client.BrowserRendering.Screenshot.New(context.TODO(), browser_rendering.ScreenshotNewParams{
    AccountID: cloudflare.F("account_id"),
    Body: browser_rendering.ScreenshotNewParamsBodyObject{
      URL: cloudflare.F("https://www.example.com/"),
    },
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", screenshot.Success)
}
{
  "success": true,
  "errors": [
    {
      "code": 0,
      "message": "message"
    }
  ]
}
{
  "errors": [
    {
      "code": 2001,
      "message": "Rate limit exceeded"
    }
  ],
  "success": false
}
Returns Examples
{
  "success": true,
  "errors": [
    {
      "code": 0,
      "message": "message"
    }
  ]
}
{
  "errors": [
    {
      "code": 2001,
      "message": "Rate limit exceeded"
    }
  ],
  "success": false
}