Skip to content

Commit 07036ad

Browse files
committed
[Browser Rendering] Small updates
1 parent 78485f3 commit 07036ad

File tree

3 files changed

+40
-44
lines changed

3 files changed

+40
-44
lines changed

src/content/docs/browser-rendering/faq.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ const innerHtml = await page.evaluate(() => {
4747

4848
Keep in mind that `page.evaluate` can only return primitive types like strings, numbers, etc.
4949

50-
Returning an `HTMLElement` won't work.
50+
Returning an `HTMLElement` will not work.
5151

5252
:::

src/content/docs/browser-rendering/how-to/pdf-generation.mdx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ npm install @cloudflare/puppeteer --save-dev
2525

2626
3. Add your Browser Rendering binding to your new `wrangler.toml` configuration:
2727

28-
```yaml
28+
```toml
2929
browser = { binding = "BROWSER" }
3030
```
3131

@@ -66,15 +66,12 @@ export default {
6666
Rather than using Browser Rendering to navigate to a user-provided URL, manually generate a webpage, then provide that webpage to the Browser Rendering instance. This allows you to render any design you want.
6767

6868
:::note
69-
It's worth noting that you can generate your HTML or CSS using any method
70-
you'd like. For now we're using string interpolation, but this method is
71-
fully-compatible with web frameworks capable of rendering HTML on Workers such
72-
as React, Remix, and Vue.
69+
You can generate your HTML or CSS using any method you like. This example uses string interpolation, but this method is fully-compatible with web frameworks capable of rendering HTML on Workers such as React, Remix, and Vue.
7370
:::
7471

7572
For this example, we're going to take in user-provided content (via a '?name=' parameter), and have that name output in the final PDF document.
7673

77-
To start, let's fill out your 'generateDocument' function with the following:
74+
To start, fill out your `generateDocument` function with the following:
7875

7976
```ts
8077
const generateDocument = (name: string) => {
@@ -128,11 +125,7 @@ const generateDocument = (name: string) => {
128125
This example HTML document should render a beige background imitating a certificate showing that the user-provided name has successfully rendered a PDF using Cloudflare Workers.
129126

130127
:::note
131-
It's usually best to avoid directly interpolating user-provided content into
132-
an image or PDF renderer in production applications. To render contents like
133-
an invoice, it wold be best to validate the data input, and fetch data
134-
yourself using tools like [D1](/d1/) or
135-
[Workers KV](/kv/).
128+
It is usually best to avoid directly interpolating user-provided content into an image or PDF renderer in production applications. To render contents like an invoice, it wold be best to validate the data input, and fetch data yourself using tools like [D1](/d1/) or [Workers KV](/kv/).
136129
:::
137130

138131
## 2. Load HTML and CSS Into Browser

src/content/docs/browser-rendering/platform/puppeteer.mdx

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The Workers team forked a version of Puppeteer and patched it to connect to the
1515

1616
Our version is open sourced and can be found in [Cloudflare's fork of Puppeteer](https://github.com/cloudflare/puppeteer). The npm can be installed from [npmjs](https://www.npmjs.com/) as [@cloudflare/puppeteer](https://www.npmjs.com/package/@cloudflare/puppeteer):
1717

18-
```javascript
18+
```bash
1919
npm install @cloudflare/puppeteer --save-dev
2020
```
2121

@@ -83,18 +83,18 @@ In order to facilitate browser session management, we've added new methods to `p
8383

8484
`puppeteer.sessions()` lists the current running sessions. It will return an output similar to this:
8585

86-
```
86+
```json
8787
[
88-
{
89-
"connectionId": "2a2246fa-e234-4dc1-8433-87e6cee80145",
90-
"connectionStartTime": 1711621704607,
91-
"sessionId": "478f4d7d-e943-40f6-a414-837d3736a1dc",
92-
"startTime": 1711621703708
93-
},
94-
{
95-
"sessionId": "565e05fb-4d2a-402b-869b-5b65b1381db7",
96-
"startTime": 1711621703808
97-
}
88+
{
89+
"connectionId": "2a2246fa-e234-4dc1-8433-87e6cee80145",
90+
"connectionStartTime": 1711621704607,
91+
"sessionId": "478f4d7d-e943-40f6-a414-837d3736a1dc",
92+
"startTime": 1711621703708
93+
},
94+
{
95+
"sessionId": "565e05fb-4d2a-402b-869b-5b65b1381db7",
96+
"startTime": 1711621703808
97+
}
9898
]
9999
```
100100

@@ -104,22 +104,22 @@ Notice that the session `478f4d7d-e943-40f6-a414-837d3736a1dc` has an active wor
104104

105105
`puppeteer.history()` lists recent sessions, both open and closed. It's useful to get a sense of your current usage.
106106

107-
```
107+
```json
108108
[
109-
{
110-
"closeReason": 2,
111-
"closeReasonText": "BrowserIdle",
112-
"endTime": 1711621769485,
113-
"sessionId": "478f4d7d-e943-40f6-a414-837d3736a1dc",
114-
"startTime": 1711621703708
115-
},
116-
{
117-
"closeReason": 1,
118-
"closeReasonText": "NormalClosure",
119-
"endTime": 1711123501771,
120-
"sessionId": "2be00a21-9fb6-4bb2-9861-8cd48e40e771",
121-
"startTime": 1711123430918
122-
}
109+
{
110+
"closeReason": 2,
111+
"closeReasonText": "BrowserIdle",
112+
"endTime": 1711621769485,
113+
"sessionId": "478f4d7d-e943-40f6-a414-837d3736a1dc",
114+
"startTime": 1711621703708
115+
},
116+
{
117+
"closeReason": 1,
118+
"closeReasonText": "NormalClosure",
119+
"endTime": 1711123501771,
120+
"sessionId": "2be00a21-9fb6-4bb2-9861-8cd48e40e771",
121+
"startTime": 1711123430918
122+
}
123123
]
124124
```
125125

@@ -131,12 +131,15 @@ You should also be able to access this information in the dashboard, albeit with
131131

132132
`puppeteer.limits()` lists your active limits:
133133

134-
```
134+
```json
135135
{
136-
"activeSessions": ["478f4d7d-e943-40f6-a414-837d3736a1dc", "565e05fb-4d2a-402b-869b-5b65b1381db7"],
137-
"allowedBrowserAcquisitions": 1,
138-
"maxConcurrentSessions": 2,
139-
"timeUntilNextAllowedBrowserAcquisition": 0
136+
"activeSessions": [
137+
"478f4d7d-e943-40f6-a414-837d3736a1dc",
138+
"565e05fb-4d2a-402b-869b-5b65b1381db7"
139+
],
140+
"allowedBrowserAcquisitions": 1,
141+
"maxConcurrentSessions": 2,
142+
"timeUntilNextAllowedBrowserAcquisition": 0
140143
}
141144
```
142145

0 commit comments

Comments
 (0)