You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/browser-rendering/get-started.mdx
+49-3Lines changed: 49 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,8 +4,54 @@ title: Get started
4
4
sidebar:
5
5
order: 2
6
6
---
7
+
import { Render } from"~/components";
7
8
8
-
Browser rendering can be used in two ways:
9
+
Cloudflare Browser Rendering allows you to programmatically control a headless browser, enabling you to do things like take screenshots, generate PDFs, and perform automated browser tasks.
9
10
10
-
-[Workers Bindings](/browser-rendering/workers-bindings/) for complex scripts.
11
-
-[REST API](/browser-rendering/rest-api/) for simple actions.
11
+
There are two ways to use Browser Rendering:
12
+
-[REST API](/browser-rendering/rest-api/) for simple, one-off actions, like taking a screenshot, fetching HTML, or generating a PDF.
13
+
-[Workers Bindings](/browser-rendering/workers-bindings/) for more complex, multi-step browser automation using [Puppeteer](/browser-rendering/platform/puppeteer/) and [Playwright](/browser-rendering/platform/playwright/).
14
+
15
+
This guide will help you choose the right path for your needs and get you started with your first Browser Rendering project.
16
+
17
+
## REST API
18
+
19
+
The REST API is best for situations where you have an existing application and want to perform simple, stateless browser actions.
20
+
21
+
### Prerequisites
22
+
- Sign up for a [Cloudflare account](https://dash.cloudflare.com/sign-up/workers-and-pages).
23
+
- Create a [Cloudflare API Token](/fundamentals/api/get-started/create-token/) with `Browser Rendering - Edit` permissions.
24
+
25
+
### Example: Take a screenshot of the Cloudflare homepage
-[Generate a PDF](/browser-rendering/rest-api/pdf-endpoint/)
36
+
-[and more...](/browser-rendering/rest-api/)
37
+
38
+
## Workers Bindings
39
+
40
+
Workers Bindings are best for situations where you need to build more complex, multi-step browser automation workflows. You can use familiar tools like [Puppeteer](/browser-rendering/platform/puppeteer/) and [Playwright](/browser-rendering/platform/playwright/).
41
+
42
+
### Prerequisites
43
+
<Renderfile="prereqs"product="workers" />
44
+
45
+
### Example: Navigate to a URL, take a screenshot, and store in KV
If you have any feature requests or notice any bugs, share your feedback directly with the Cloudflare team by joining the [Cloudflare Developers community on Discord](https://discord.cloudflare.com/).
54
+
55
+
- Check out all the [REST API endpoints](/browser-rendering/rest-api/)
56
+
- Try out the [Playwright MCP](/browser-rendering/platform/playwright-mcp/)
57
+
- Learn more about Browser Rendering [limits](/browser-rendering/platform/limits/) and [pricing](/browser-rendering/platform/pricing/).
Copy file name to clipboardExpand all lines: src/content/docs/browser-rendering/workers-bindings/screenshots.mdx
+2-165Lines changed: 2 additions & 165 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,174 +17,11 @@ By following this guide, you will create a Worker that uses the Browser Renderin
17
17
18
18
<Renderfile="prereqs"product="workers" />
19
19
20
-
## 1. Create a Worker project
21
-
22
-
[Cloudflare Workers](/workers/) provides a serverless execution environment that allows you to create new applications or augment existing ones without configuring or maintaining infrastructure. Your Worker application is a container to interact with a headless browser to do actions, such as taking screenshots.
23
-
24
-
Create a new Worker project named `browser-worker` by running:
In your `browser-worker` directory, install Cloudflare’s [fork of Puppeteer](/browser-rendering/platform/puppeteer/):
45
-
46
-
<PackageManagerspkg="@cloudflare/puppeteer"dev />
47
-
48
-
## 3. Create a KV namespace
49
-
50
-
Browser Rendering can be used with other developer products. You might need a [relational database](/d1/), an [R2 bucket](/r2/) to archive your crawled pages and assets, a [Durable Object](/durable-objects/) to keep your browser instance alive and share it with multiple requests, or [Queues](/queues/) to handle your jobs asynchronous.
51
-
52
-
For the purpose of this guide, you are going to use a [KV store](/kv/concepts/kv-namespaces/) to cache your screenshots.
53
-
54
-
Create two namespaces, one for production, and one for development.
Configure your `browser-worker` project's [Wrangler configuration file](/workers/wrangler/configuration/) by adding a browser [binding](/workers/runtime-apis/bindings/) and a [Node.js compatibility flag](/workers/configuration/compatibility-flags/#nodejs-compatibility-flag). Bindings allow your Workers to interact with resources on the Cloudflare developer platform. Your browser `binding` name is set by you, this guide uses the name `MYBROWSER`. Browser bindings allow for communication between a Worker and a headless browser which allows you to do actions such as taking a screenshot, generating a PDF and more.
66
-
67
-
Update your [Wrangler configuration file](/workers/wrangler/configuration/) with the Browser Rendering API binding and the KV namespaces you created:
returnnewResponse("Please add an ?url=https://example.com/ parameter");
159
-
}
160
-
},
161
-
} satisfiesExportedHandler<Env>;
162
-
```
163
-
164
-
</TabItem> </Tabs>
165
-
166
-
This Worker instantiates a browser using Puppeteer, opens a new page, navigates to what you put in the `"url"` parameter, takes a screenshot of the page, stores the screenshot in KV, closes the browser, and responds with the JPEG image of the screenshot.
167
-
168
-
If your Worker is running in production, it will store the screenshot to the production KV namespace. If you are running `wrangler dev`, it will store the screenshot to the dev KV namespace.
169
-
170
-
If the same `"url"` is requested again, it will use the cached version in KV instead, unless it expired.
171
-
172
-
## 6. Test
173
-
174
-
Run `npx wrangler dev` to test your Worker locally. You can also use [remote bindings](/workers/development-testing/#remote-bindings) to test against a remote browser.
175
-
176
-
To test taking your first screenshot, go to the following URL:
177
-
178
-
`<LOCAL_HOST_URL>/?url=https://example.com`
179
-
180
-
## 7. Deploy
181
-
182
-
Run `npx wrangler deploy` to deploy your Worker to the Cloudflare global network.
183
-
184
-
To take your first screenshot, go to the following URL:
0 commit comments