Cloudflare Browser

Configure Cloudflare Browser Rendering through the official `cloudflare` package.

Use Cloudflare Browser Rendering when browser automation should run through Cloudflare's REST API. ViteHub uses the official cloudflare package for one-shot operations such as content(), screenshot(), pdf(), snapshot(), links(), markdown(), json(), scrape(), and crawl().

Before you start

Install cloudflare alongside @vitehub/browser.

Terminal
pnpm add https://pkg.pr.new/vite-hub/vitehub/@vitehub/browser@main cloudflare

Set CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID in the runtime environment, or provide apiToken and accountId in top-level browser config.

.env
CLOUDFLARE_ACCOUNT_ID=your-account-id
CLOUDFLARE_API_TOKEN=your-api-token

ViteHub does not load .env files for you. Your app or runtime must load them into process.env.

Configure Cloudflare

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@vitehub/browser/nuxt'],
  browser: {
    provider: 'cloudflare',
    accountId: process.env.CLOUDFLARE_ACCOUNT_ID,
  },
})

On Cloudflare hosting, ViteHub uses the Cloudflare browser provider automatically. Set browser.provider = 'cloudflare' when you want to force the same provider outside Cloudflare too.

Cloudflare-specific options

Set Cloudflare-specific values in top-level browser config, not in defineBrowser().

OptionUse it for
accountIdSelect the Cloudflare account used for Browser Rendering.
apiTokenOverride CLOUDFLARE_API_TOKEN explicitly.
baseURLPoint the SDK at a custom Cloudflare API base URL when needed.

Define a browser

Cloudflare is strongest when your definitions call the capability client directly.

server/browsers/pdf-report.ts
export default defineBrowser(async (payload: { url: string }, { browser }) => {
  return {
    pdf: await browser.pdf({
      pdf: {
        printBackground: true,
      },
      url: payload.url,
    }),
  }
}, {
  timeout: 15_000,
})

What changes on Cloudflare

ConcernBehavior
Credential resolutionViteHub reads accountId and apiToken from config or CLOUDFLARE_ACCOUNT_ID / CLOUDFLARE_API_TOKEN.
SessionsCloudflare does not expose createSession(), getSession(), or closeSession() through ViteHub. Check browser.capabilities before calling them.
Crawlbrowser.crawl() returns a job handle with status(), results(), and cancel().
Native paritybrowser.native exposes the raw Cloudflare SDK client when you need Cloudflare's API directly.
On Nitro or Nuxt, keep browser.provider = 'cloudflare' in config and use runtime-config overrides such as NITRO_BROWSER_ACCOUNT_ID, NITRO_BROWSER_API_TOKEN, NUXT_BROWSER_ACCOUNT_ID, or NUXT_BROWSER_API_TOKEN when you need per-environment credentials.
Choose Cloudflare when the work naturally maps to Browser Rendering's REST operations and you want direct access to Cloudflare's extraction and crawl features.