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.

CacheTTL param.Field[float64]Optional

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

maximum86400
minimum0
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[[]ScreenshotNewParamsAddScriptTag]Optional

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

ID stringOptional
Content stringOptional
Type stringOptional
URL stringOptional
formaturi
AddStyleTag param.Field[[]ScreenshotNewParamsAddStyleTag]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
formaturi
AllowRequestPattern param.Field[[]string]Optional

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

AllowResourceTypes param.Field[[]ScreenshotNewParamsAllowResourceType]Optional

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

const ScreenshotNewParamsAllowResourceTypeDocument ScreenshotNewParamsAllowResourceType = "document"
const ScreenshotNewParamsAllowResourceTypeStylesheet ScreenshotNewParamsAllowResourceType = "stylesheet"
const ScreenshotNewParamsAllowResourceTypeImage ScreenshotNewParamsAllowResourceType = "image"
const ScreenshotNewParamsAllowResourceTypeMedia ScreenshotNewParamsAllowResourceType = "media"
const ScreenshotNewParamsAllowResourceTypeFont ScreenshotNewParamsAllowResourceType = "font"
const ScreenshotNewParamsAllowResourceTypeScript ScreenshotNewParamsAllowResourceType = "script"
const ScreenshotNewParamsAllowResourceTypeTexttrack ScreenshotNewParamsAllowResourceType = "texttrack"
const ScreenshotNewParamsAllowResourceTypeXHR ScreenshotNewParamsAllowResourceType = "xhr"
const ScreenshotNewParamsAllowResourceTypeFetch ScreenshotNewParamsAllowResourceType = "fetch"
const ScreenshotNewParamsAllowResourceTypePrefetch ScreenshotNewParamsAllowResourceType = "prefetch"
const ScreenshotNewParamsAllowResourceTypeEventsource ScreenshotNewParamsAllowResourceType = "eventsource"
const ScreenshotNewParamsAllowResourceTypeWebsocket ScreenshotNewParamsAllowResourceType = "websocket"
const ScreenshotNewParamsAllowResourceTypeManifest ScreenshotNewParamsAllowResourceType = "manifest"
const ScreenshotNewParamsAllowResourceTypeSignedexchange ScreenshotNewParamsAllowResourceType = "signedexchange"
const ScreenshotNewParamsAllowResourceTypePing ScreenshotNewParamsAllowResourceType = "ping"
const ScreenshotNewParamsAllowResourceTypeCspviolationreport ScreenshotNewParamsAllowResourceType = "cspviolationreport"
const ScreenshotNewParamsAllowResourceTypePreflight ScreenshotNewParamsAllowResourceType = "preflight"
const ScreenshotNewParamsAllowResourceTypeOther ScreenshotNewParamsAllowResourceType = "other"
Authenticate param.Field[ScreenshotNewParamsAuthenticate]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[[]ScreenshotNewParamsCookie]Optional

Body param: Check options.

Name string

Cookie name.

Value string
Domain stringOptional
Expires float64Optional
HTTPOnly boolOptional
PartitionKey stringOptional
Path stringOptional
Priority ScreenshotNewParamsCookiesPriorityOptional
One of the following:
const ScreenshotNewParamsCookiesPriorityLow ScreenshotNewParamsCookiesPriority = "Low"
const ScreenshotNewParamsCookiesPriorityMedium ScreenshotNewParamsCookiesPriority = "Medium"
const ScreenshotNewParamsCookiesPriorityHigh ScreenshotNewParamsCookiesPriority = "High"
SameParty boolOptional
SameSite ScreenshotNewParamsCookiesSameSiteOptional
One of the following:
const ScreenshotNewParamsCookiesSameSiteStrict ScreenshotNewParamsCookiesSameSite = "Strict"
const ScreenshotNewParamsCookiesSameSiteLax ScreenshotNewParamsCookiesSameSite = "Lax"
const ScreenshotNewParamsCookiesSameSiteNone ScreenshotNewParamsCookiesSameSite = "None"
Secure boolOptional
SourcePort float64Optional
SourceScheme ScreenshotNewParamsCookiesSourceSchemeOptional
One of the following:
const ScreenshotNewParamsCookiesSourceSchemeUnset ScreenshotNewParamsCookiesSourceScheme = "Unset"
const ScreenshotNewParamsCookiesSourceSchemeNonSecure ScreenshotNewParamsCookiesSourceScheme = "NonSecure"
const ScreenshotNewParamsCookiesSourceSchemeSecure ScreenshotNewParamsCookiesSourceScheme = "Secure"
URL stringOptional
EmulateMediaType param.Field[string]Optional

Body param

GotoOptions param.Field[ScreenshotNewParamsGotoOptions]Optional

Body param: Check options.

Referer stringOptional
ReferrerPolicy stringOptional
Timeout float64Optional
maximum60000
WaitUntil ScreenshotNewParamsGotoOptionsWaitUntilUnionOptional
One of the following:
type ScreenshotNewParamsGotoOptionsWaitUntilString string
One of the following:
const ScreenshotNewParamsGotoOptionsWaitUntilStringLoad ScreenshotNewParamsGotoOptionsWaitUntilString = "load"
const ScreenshotNewParamsGotoOptionsWaitUntilStringDomcontentloaded ScreenshotNewParamsGotoOptionsWaitUntilString = "domcontentloaded"
const ScreenshotNewParamsGotoOptionsWaitUntilStringNetworkidle0 ScreenshotNewParamsGotoOptionsWaitUntilString = "networkidle0"
const ScreenshotNewParamsGotoOptionsWaitUntilStringNetworkidle2 ScreenshotNewParamsGotoOptionsWaitUntilString = "networkidle2"
type ScreenshotNewParamsGotoOptionsWaitUntilArray []ScreenshotNewParamsGotoOptionsWaitUntilArray
One of the following:
const ScreenshotNewParamsGotoOptionsWaitUntilArrayItemLoad ScreenshotNewParamsGotoOptionsWaitUntilArrayItem = "load"
const ScreenshotNewParamsGotoOptionsWaitUntilArrayItemDomcontentloaded ScreenshotNewParamsGotoOptionsWaitUntilArrayItem = "domcontentloaded"
const ScreenshotNewParamsGotoOptionsWaitUntilArrayItemNetworkidle0 ScreenshotNewParamsGotoOptionsWaitUntilArrayItem = "networkidle0"
const ScreenshotNewParamsGotoOptionsWaitUntilArrayItemNetworkidle2 ScreenshotNewParamsGotoOptionsWaitUntilArrayItem = "networkidle2"
HTML param.Field[string]Optional

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

minLength1
RejectRequestPattern param.Field[[]string]Optional

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

RejectResourceTypes param.Field[[]ScreenshotNewParamsRejectResourceType]Optional

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

const ScreenshotNewParamsRejectResourceTypeDocument ScreenshotNewParamsRejectResourceType = "document"
const ScreenshotNewParamsRejectResourceTypeStylesheet ScreenshotNewParamsRejectResourceType = "stylesheet"
const ScreenshotNewParamsRejectResourceTypeImage ScreenshotNewParamsRejectResourceType = "image"
const ScreenshotNewParamsRejectResourceTypeMedia ScreenshotNewParamsRejectResourceType = "media"
const ScreenshotNewParamsRejectResourceTypeFont ScreenshotNewParamsRejectResourceType = "font"
const ScreenshotNewParamsRejectResourceTypeScript ScreenshotNewParamsRejectResourceType = "script"
const ScreenshotNewParamsRejectResourceTypeTexttrack ScreenshotNewParamsRejectResourceType = "texttrack"
const ScreenshotNewParamsRejectResourceTypeXHR ScreenshotNewParamsRejectResourceType = "xhr"
const ScreenshotNewParamsRejectResourceTypeFetch ScreenshotNewParamsRejectResourceType = "fetch"
const ScreenshotNewParamsRejectResourceTypePrefetch ScreenshotNewParamsRejectResourceType = "prefetch"
const ScreenshotNewParamsRejectResourceTypeEventsource ScreenshotNewParamsRejectResourceType = "eventsource"
const ScreenshotNewParamsRejectResourceTypeWebsocket ScreenshotNewParamsRejectResourceType = "websocket"
const ScreenshotNewParamsRejectResourceTypeManifest ScreenshotNewParamsRejectResourceType = "manifest"
const ScreenshotNewParamsRejectResourceTypeSignedexchange ScreenshotNewParamsRejectResourceType = "signedexchange"
const ScreenshotNewParamsRejectResourceTypePing ScreenshotNewParamsRejectResourceType = "ping"
const ScreenshotNewParamsRejectResourceTypeCspviolationreport ScreenshotNewParamsRejectResourceType = "cspviolationreport"
const ScreenshotNewParamsRejectResourceTypePreflight ScreenshotNewParamsRejectResourceType = "preflight"
const ScreenshotNewParamsRejectResourceTypeOther ScreenshotNewParamsRejectResourceType = "other"
ScreenshotOptions param.Field[ScreenshotNewParamsScreenshotOptions]Optional

Body param: Check options.

CaptureBeyondViewport boolOptional
Clip ScreenshotNewParamsScreenshotOptionsClipOptional
Height float64
Width float64
X float64
Y float64
Scale float64Optional
Encoding ScreenshotNewParamsScreenshotOptionsEncodingOptional
One of the following:
const ScreenshotNewParamsScreenshotOptionsEncodingBinary ScreenshotNewParamsScreenshotOptionsEncoding = "binary"
const ScreenshotNewParamsScreenshotOptionsEncodingBase64 ScreenshotNewParamsScreenshotOptionsEncoding = "base64"
FromSurface boolOptional
FullPage boolOptional
OmitBackground boolOptional
OptimizeForSpeed boolOptional
Quality float64Optional
Type ScreenshotNewParamsScreenshotOptionsTypeOptional
One of the following:
const ScreenshotNewParamsScreenshotOptionsTypePNG ScreenshotNewParamsScreenshotOptionsType = "png"
const ScreenshotNewParamsScreenshotOptionsTypeJPEG ScreenshotNewParamsScreenshotOptionsType = "jpeg"
const ScreenshotNewParamsScreenshotOptionsTypeWebP ScreenshotNewParamsScreenshotOptionsType = "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

URL param.Field[string]Optional

Body param: URL to navigate to, eg. https://example.com.

formaturi
UserAgent param.Field[string]Optional

Body param

Viewport param.Field[ScreenshotNewParamsViewport]Optional

Body param: Check options.

Height float64
Width float64
DeviceScaleFactor float64Optional
HasTouch boolOptional
IsLandscape boolOptional
IsMobile boolOptional
WaitForSelector param.Field[ScreenshotNewParamsWaitForSelector]Optional

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

Selector string
Hidden ScreenshotNewParamsWaitForSelectorHiddenOptional
Timeout float64Optional
maximum120000
Visible ScreenshotNewParamsWaitForSelectorVisibleOptional
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"),
    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
}