Skip to content
Start here

Get HTML content and screenshot.

client.BrowserRendering.Snapshot.New(ctx, params) (*SnapshotNewResponse, error)
POST/accounts/{account_id}/browser-rendering/snapshot

Returns the page’s HTML content and screenshot. 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 SnapshotNewParams
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[[]SnapshotNewParamsAddScriptTag]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[[]SnapshotNewParamsAddStyleTag]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[[]SnapshotNewParamsAllowResourceType]Optional

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

const SnapshotNewParamsAllowResourceTypeDocument SnapshotNewParamsAllowResourceType = "document"
const SnapshotNewParamsAllowResourceTypeStylesheet SnapshotNewParamsAllowResourceType = "stylesheet"
const SnapshotNewParamsAllowResourceTypeImage SnapshotNewParamsAllowResourceType = "image"
const SnapshotNewParamsAllowResourceTypeMedia SnapshotNewParamsAllowResourceType = "media"
const SnapshotNewParamsAllowResourceTypeFont SnapshotNewParamsAllowResourceType = "font"
const SnapshotNewParamsAllowResourceTypeScript SnapshotNewParamsAllowResourceType = "script"
const SnapshotNewParamsAllowResourceTypeTexttrack SnapshotNewParamsAllowResourceType = "texttrack"
const SnapshotNewParamsAllowResourceTypeXHR SnapshotNewParamsAllowResourceType = "xhr"
const SnapshotNewParamsAllowResourceTypeFetch SnapshotNewParamsAllowResourceType = "fetch"
const SnapshotNewParamsAllowResourceTypePrefetch SnapshotNewParamsAllowResourceType = "prefetch"
const SnapshotNewParamsAllowResourceTypeEventsource SnapshotNewParamsAllowResourceType = "eventsource"
const SnapshotNewParamsAllowResourceTypeWebsocket SnapshotNewParamsAllowResourceType = "websocket"
const SnapshotNewParamsAllowResourceTypeManifest SnapshotNewParamsAllowResourceType = "manifest"
const SnapshotNewParamsAllowResourceTypeSignedexchange SnapshotNewParamsAllowResourceType = "signedexchange"
const SnapshotNewParamsAllowResourceTypePing SnapshotNewParamsAllowResourceType = "ping"
const SnapshotNewParamsAllowResourceTypeCspviolationreport SnapshotNewParamsAllowResourceType = "cspviolationreport"
const SnapshotNewParamsAllowResourceTypePreflight SnapshotNewParamsAllowResourceType = "preflight"
const SnapshotNewParamsAllowResourceTypeOther SnapshotNewParamsAllowResourceType = "other"
Authenticate param.Field[SnapshotNewParamsAuthenticate]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[[]SnapshotNewParamsCookie]Optional

Body param: Check options.

Name string

Cookie name.

Value string
Domain stringOptional
Expires float64Optional
HTTPOnly boolOptional
PartitionKey stringOptional
Path stringOptional
Priority SnapshotNewParamsCookiesPriorityOptional
One of the following:
const SnapshotNewParamsCookiesPriorityLow SnapshotNewParamsCookiesPriority = "Low"
const SnapshotNewParamsCookiesPriorityMedium SnapshotNewParamsCookiesPriority = "Medium"
const SnapshotNewParamsCookiesPriorityHigh SnapshotNewParamsCookiesPriority = "High"
SameParty boolOptional
SameSite SnapshotNewParamsCookiesSameSiteOptional
One of the following:
const SnapshotNewParamsCookiesSameSiteStrict SnapshotNewParamsCookiesSameSite = "Strict"
const SnapshotNewParamsCookiesSameSiteLax SnapshotNewParamsCookiesSameSite = "Lax"
const SnapshotNewParamsCookiesSameSiteNone SnapshotNewParamsCookiesSameSite = "None"
Secure boolOptional
SourcePort float64Optional
SourceScheme SnapshotNewParamsCookiesSourceSchemeOptional
One of the following:
const SnapshotNewParamsCookiesSourceSchemeUnset SnapshotNewParamsCookiesSourceScheme = "Unset"
const SnapshotNewParamsCookiesSourceSchemeNonSecure SnapshotNewParamsCookiesSourceScheme = "NonSecure"
const SnapshotNewParamsCookiesSourceSchemeSecure SnapshotNewParamsCookiesSourceScheme = "Secure"
URL stringOptional
EmulateMediaType param.Field[string]Optional

Body param

Formats param.Field[[]SnapshotNewParamsFormat]Optional

Body param

const SnapshotNewParamsFormatContent SnapshotNewParamsFormat = "content"
const SnapshotNewParamsFormatScreenshot SnapshotNewParamsFormat = "screenshot"
const SnapshotNewParamsFormatMarkdown SnapshotNewParamsFormat = "markdown"
const SnapshotNewParamsFormatAccessibilityTree SnapshotNewParamsFormat = "accessibilityTree"
GotoOptions param.Field[SnapshotNewParamsGotoOptions]Optional

Body param: Check options.

Referer stringOptional
ReferrerPolicy stringOptional
Timeout float64Optional
maximum60000
WaitUntil SnapshotNewParamsGotoOptionsWaitUntilUnionOptional
One of the following:
type SnapshotNewParamsGotoOptionsWaitUntilString string
One of the following:
const SnapshotNewParamsGotoOptionsWaitUntilStringLoad SnapshotNewParamsGotoOptionsWaitUntilString = "load"
const SnapshotNewParamsGotoOptionsWaitUntilStringDomcontentloaded SnapshotNewParamsGotoOptionsWaitUntilString = "domcontentloaded"
const SnapshotNewParamsGotoOptionsWaitUntilStringNetworkidle0 SnapshotNewParamsGotoOptionsWaitUntilString = "networkidle0"
const SnapshotNewParamsGotoOptionsWaitUntilStringNetworkidle2 SnapshotNewParamsGotoOptionsWaitUntilString = "networkidle2"
type SnapshotNewParamsGotoOptionsWaitUntilArray []SnapshotNewParamsGotoOptionsWaitUntilArray
One of the following:
const SnapshotNewParamsGotoOptionsWaitUntilArrayItemLoad SnapshotNewParamsGotoOptionsWaitUntilArrayItem = "load"
const SnapshotNewParamsGotoOptionsWaitUntilArrayItemDomcontentloaded SnapshotNewParamsGotoOptionsWaitUntilArrayItem = "domcontentloaded"
const SnapshotNewParamsGotoOptionsWaitUntilArrayItemNetworkidle0 SnapshotNewParamsGotoOptionsWaitUntilArrayItem = "networkidle0"
const SnapshotNewParamsGotoOptionsWaitUntilArrayItemNetworkidle2 SnapshotNewParamsGotoOptionsWaitUntilArrayItem = "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[[]SnapshotNewParamsRejectResourceType]Optional

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

const SnapshotNewParamsRejectResourceTypeDocument SnapshotNewParamsRejectResourceType = "document"
const SnapshotNewParamsRejectResourceTypeStylesheet SnapshotNewParamsRejectResourceType = "stylesheet"
const SnapshotNewParamsRejectResourceTypeImage SnapshotNewParamsRejectResourceType = "image"
const SnapshotNewParamsRejectResourceTypeMedia SnapshotNewParamsRejectResourceType = "media"
const SnapshotNewParamsRejectResourceTypeFont SnapshotNewParamsRejectResourceType = "font"
const SnapshotNewParamsRejectResourceTypeScript SnapshotNewParamsRejectResourceType = "script"
const SnapshotNewParamsRejectResourceTypeTexttrack SnapshotNewParamsRejectResourceType = "texttrack"
const SnapshotNewParamsRejectResourceTypeXHR SnapshotNewParamsRejectResourceType = "xhr"
const SnapshotNewParamsRejectResourceTypeFetch SnapshotNewParamsRejectResourceType = "fetch"
const SnapshotNewParamsRejectResourceTypePrefetch SnapshotNewParamsRejectResourceType = "prefetch"
const SnapshotNewParamsRejectResourceTypeEventsource SnapshotNewParamsRejectResourceType = "eventsource"
const SnapshotNewParamsRejectResourceTypeWebsocket SnapshotNewParamsRejectResourceType = "websocket"
const SnapshotNewParamsRejectResourceTypeManifest SnapshotNewParamsRejectResourceType = "manifest"
const SnapshotNewParamsRejectResourceTypeSignedexchange SnapshotNewParamsRejectResourceType = "signedexchange"
const SnapshotNewParamsRejectResourceTypePing SnapshotNewParamsRejectResourceType = "ping"
const SnapshotNewParamsRejectResourceTypeCspviolationreport SnapshotNewParamsRejectResourceType = "cspviolationreport"
const SnapshotNewParamsRejectResourceTypePreflight SnapshotNewParamsRejectResourceType = "preflight"
const SnapshotNewParamsRejectResourceTypeOther SnapshotNewParamsRejectResourceType = "other"
ScreenshotOptions param.Field[SnapshotNewParamsScreenshotOptions]Optional

Body param

CaptureBeyondViewport boolOptional
Clip SnapshotNewParamsScreenshotOptionsClipOptional
Height float64
Width float64
X float64
Y float64
Scale float64Optional
FromSurface boolOptional
FullPage boolOptional
OmitBackground boolOptional
OptimizeForSpeed boolOptional
Quality float64Optional
Type SnapshotNewParamsScreenshotOptionsTypeOptional
One of the following:
const SnapshotNewParamsScreenshotOptionsTypePNG SnapshotNewParamsScreenshotOptionsType = "png"
const SnapshotNewParamsScreenshotOptionsTypeJPEG SnapshotNewParamsScreenshotOptionsType = "jpeg"
const SnapshotNewParamsScreenshotOptionsTypeWebP SnapshotNewParamsScreenshotOptionsType = "webp"
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[SnapshotNewParamsViewport]Optional

Body param: Check options.

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

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

Selector string
Hidden SnapshotNewParamsWaitForSelectorHiddenOptional
Timeout float64Optional
maximum120000
Visible SnapshotNewParamsWaitForSelectorVisibleOptional
WaitForTimeout param.Field[float64]Optional

Body param: Waits for a specified timeout before continuing.

maximum120000
ReturnsExpand Collapse
type SnapshotNewResponse struct{…}
AccessibilityTree SnapshotNewResponseAccessibilityTreeOptional

Accessibility tree node

Role string
Autocomplete stringOptional
Checked SnapshotNewResponseAccessibilityTreeCheckedUnionOptional
One of the following:
UnionBool
type SnapshotNewResponseAccessibilityTreeCheckedString string
Children []unknownOptional
Description stringOptional
Disabled boolOptional
Expanded boolOptional
Focused boolOptional
Haspopup stringOptional
Invalid stringOptional
Keyshortcuts stringOptional
Level float64Optional
Multiline boolOptional
Multiselectable boolOptional
Name stringOptional
Orientation stringOptional
Pressed SnapshotNewResponseAccessibilityTreePressedUnionOptional
One of the following:
UnionBool
type SnapshotNewResponseAccessibilityTreePressedString string
Readonly boolOptional
Required boolOptional
Roledescription stringOptional
Selected boolOptional
Value SnapshotNewResponseAccessibilityTreeValueUnionOptional
One of the following:
UnionString
UnionFloat
Valuemax float64Optional
Valuemin float64Optional
Valuetext stringOptional
Content stringOptional

HTML content.

Markdown stringOptional

Markdown content. Prefixed with YAML frontmatter (e.g. title) when the page provides that metadata.

Screenshot stringOptional

Base64 encoded image.

Get HTML content and 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"),
  )
  snapshot, err := client.BrowserRendering.Snapshot.New(context.TODO(), browser_rendering.SnapshotNewParams{
    AccountID: cloudflare.F("account_id"),
    Formats: cloudflare.F([]browser_rendering.SnapshotNewParamsFormat{browser_rendering.SnapshotNewParamsFormatContent, browser_rendering.SnapshotNewParamsFormatScreenshot}),
    URL: cloudflare.F("https://www.example.com/"),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", snapshot.AccessibilityTree)
}
{
  "meta": {
    "headers": {
      "foo": "string"
    },
    "status": 0,
    "title": "title"
  },
  "success": true,
  "errors": [
    {
      "code": 0,
      "message": "message"
    }
  ],
  "result": {
    "accessibilityTree": {
      "role": "role",
      "autocomplete": "autocomplete",
      "checked": "mixed",
      "children": [
        {}
      ],
      "description": "description",
      "disabled": true,
      "expanded": true,
      "focused": true,
      "haspopup": "haspopup",
      "invalid": "invalid",
      "keyshortcuts": "keyshortcuts",
      "level": 0,
      "modal": true,
      "multiline": true,
      "multiselectable": true,
      "name": "name",
      "orientation": "orientation",
      "pressed": "mixed",
      "readonly": true,
      "required": true,
      "roledescription": "roledescription",
      "selected": true,
      "value": "string",
      "valuemax": 0,
      "valuemin": 0,
      "valuetext": "valuetext"
    },
    "content": "content",
    "markdown": "markdown",
    "screenshot": "screenshot"
  }
}
{
  "errors": [
    {
      "code": 2001,
      "message": "Rate limit exceeded"
    }
  ],
  "success": false
}
Returns Examples
{
  "meta": {
    "headers": {
      "foo": "string"
    },
    "status": 0,
    "title": "title"
  },
  "success": true,
  "errors": [
    {
      "code": 0,
      "message": "message"
    }
  ],
  "result": {
    "accessibilityTree": {
      "role": "role",
      "autocomplete": "autocomplete",
      "checked": "mixed",
      "children": [
        {}
      ],
      "description": "description",
      "disabled": true,
      "expanded": true,
      "focused": true,
      "haspopup": "haspopup",
      "invalid": "invalid",
      "keyshortcuts": "keyshortcuts",
      "level": 0,
      "modal": true,
      "multiline": true,
      "multiselectable": true,
      "name": "name",
      "orientation": "orientation",
      "pressed": "mixed",
      "readonly": true,
      "required": true,
      "roledescription": "roledescription",
      "selected": true,
      "value": "string",
      "valuemax": 0,
      "valuemin": 0,
      "valuetext": "valuetext"
    },
    "content": "content",
    "markdown": "markdown",
    "screenshot": "screenshot"
  }
}
{
  "errors": [
    {
      "code": 2001,
      "message": "Rate limit exceeded"
    }
  ],
  "success": false
}