Cloudflare Browser
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.
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.
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
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().
| Option | Use it for |
|---|---|
accountId | Select the Cloudflare account used for Browser Rendering. |
apiToken | Override CLOUDFLARE_API_TOKEN explicitly. |
baseURL | Point 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.
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
| Concern | Behavior |
|---|---|
| Credential resolution | ViteHub reads accountId and apiToken from config or CLOUDFLARE_ACCOUNT_ID / CLOUDFLARE_API_TOKEN. |
| Sessions | Cloudflare does not expose createSession(), getSession(), or closeSession() through ViteHub. Check browser.capabilities before calling them. |
| Crawl | browser.crawl() returns a job handle with status(), results(), and cancel(). |
| Native parity | browser.native exposes the raw Cloudflare SDK client when you need Cloudflare's API directly. |
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.