Skip to content

Commit 9280c7a

Browse files
committed
more updates
1 parent d1058af commit 9280c7a

File tree

10 files changed

+64
-73
lines changed

10 files changed

+64
-73
lines changed

src/content/changelog/browser-rendering/2025-04-04-playwright-beta.mdx

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,38 @@ We're excited to share that you can now use Playwright's browser automation [cap
1313
Below is an example of how to use Playwright with Browser Rendering to test a TODO application using assertions:
1414

1515
```ts title="Assertion example"
16-
import type { Fetcher } from '@cloudflare/workers-types';
17-
import { launch } from '@cloudflare/playwright';
18-
import { expect } from '@cloudflare/playwright/test';
16+
import { launch } from "@cloudflare/playwright";
17+
import { expect } from "@cloudflare/playwright/test";
1918

2019
interface Env {
21-
MYBROWSER: Fetcher;
20+
MYBROWSER: Fetcher;
2221
}
2322

2423
export default {
25-
async fetch(request: Request, env: Env) {
26-
27-
const browser = await launch(env.MYBROWSER);
28-
const page = await browser.newPage();
29-
30-
await page.goto('https://demo.playwright.dev/todomvc');
31-
32-
const TODO_ITEMS = todos.length > 0 ? todos : [
33-
'buy some cheese',
34-
'feed the cat',
35-
'book a doctors appointment'
36-
];
37-
38-
const newTodo = page.getByPlaceholder('What needs to be done?');
39-
for (const item of TODO_ITEMS) {
40-
await newTodo.fill(item);
41-
await newTodo.press('Enter');
42-
}
43-
44-
await expect(page.getByTestId('todo-title')).toHaveCount(TODO_ITEMS.length);
45-
46-
await Promise.all(TODO_ITEMS.map(
47-
(value, index) => expect(page.getByTestId('todo-title').nth(index)).toHaveText(value)
48-
));
24+
async fetch(request: Request, env: Env) {
25+
const browser = await launch(env.MYBROWSER);
26+
const page = await browser.newPage();
27+
28+
await page.goto("https://demo.playwright.dev/todomvc");
29+
30+
const TODO_ITEMS =
31+
todos.length > 0
32+
? todos
33+
: ["buy some cheese", "feed the cat", "book a doctors appointment"];
34+
35+
const newTodo = page.getByPlaceholder("What needs to be done?");
36+
for (const item of TODO_ITEMS) {
37+
await newTodo.fill(item);
38+
await newTodo.press("Enter");
39+
}
40+
41+
await expect(page.getByTestId("todo-title")).toHaveCount(TODO_ITEMS.length);
42+
43+
await Promise.all(
44+
TODO_ITEMS.map((value, index) =>
45+
expect(page.getByTestId("todo-title").nth(index)).toHaveText(value),
46+
),
47+
);
4948
},
5049
};
5150
```

src/content/docs/ai-gateway/integrations/worker-binding-methods.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ binding = "AI"
2525

2626
This configuration sets up the AI binding accessible in your Worker code as `env.AI`.
2727

28+
<Render file="wrangler-typegen" />
29+
2830
## 2. Basic Usage with Workers AI + Gateway
2931

3032
To perform an inference task using Workers AI and an AI Gateway, you can use the following code:
@@ -78,7 +80,7 @@ gateway.patchLog("my-log-id", {
7880

7981
### 3.2. `getLog`: Read Log Details
8082

81-
The `getLog` method retrieves details of a specific log ID. It returns an object of type `Promise<AiGatewayLog>`. If this type is missing, ensure you have run [`wrangler types`](/workers/languages/typescript/#generate-types)
83+
The `getLog` method retrieves details of a specific log ID. It returns an object of type `Promise<AiGatewayLog>`. If this type is missing, ensure you have run [`wrangler types`](/workers/languages/typescript/#generate-types).
8284

8385
```typescript
8486
const log = await gateway.getLog("my-log-id");

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ binding = "MYBROWSER"
4242

4343
</WranglerConfig>
4444

45+
<Render file="wrangler-typegen" />
46+
4547
Install the npm package:
4648

4749
```bash
@@ -55,13 +57,8 @@ Let's look at some examples of how to use Playwright:
5557
Using browser automation to take screenshots of web pages is a common use case. This script tells the browser to navigate to https://demo.playwright.dev/todomvc, create some items, take a screenshot of the page, and return the image in the response.
5658

5759
```ts
58-
import type { Fetcher } from '@cloudflare/workers-types';
5960
import { launch } from '@cloudflare/playwright';
6061

61-
interface Env {
62-
MYBROWSER: Fetcher;
63-
}
64-
6562
export default {
6663
async fetch(request: Request, env: Env) {
6764

@@ -103,14 +100,9 @@ A Playwright trace is a detailed log of your workflow execution that captures in
103100
Here's an example of a worker generating a trace file:
104101

105102
```ts
106-
import type { Fetcher } from '@cloudflare/workers-types';
107103
import { launch, fs } from "@cloudflare/playwright";
108104
import fs from '@cloudflare/playwright/fs';
109105

110-
interface Env {
111-
MYBROWSER: Fetcher;
112-
}
113-
114106
export default {
115107
async fetch(request: Request, env: Env) {
116108
const { searchParams } = new URL(request.url);
@@ -172,14 +164,9 @@ export default {
172164
One of the most common use cases for using Playwright is software testing. Playwright includes test assertion features in its APIs; refer to [Assertions](https://playwright.dev/docs/test-assertions) in the Playwright documentation for details. Here's an example of a Worker doing `expect()` test assertions of the [todomvc](https://demo.playwright.dev/todomvc) demo page:
173165

174166
```ts
175-
import type { Fetcher } from '@cloudflare/workers-types';
176167
import { launch } from '@cloudflare/playwright';
177168
import { expect } from '@cloudflare/playwright/test';
178169

179-
interface Env {
180-
MYBROWSER: Fetcher;
181-
}
182-
183170
export default {
184171
async fetch(request: Request, env: Env) {
185172

src/content/docs/d1/worker-api/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Refer to the relevant sections for the API documentation.
1818

1919
## TypeScript support
2020

21-
D1 Worker Bindings API is fully-typed via the types generated by running [`wrangler types`](/workers/languages/typescript/#typescript) package, and also supports [generic types](https://www.typescriptlang.org/docs/handbook/2/generics.html#generic-types) as part of its TypeScript API. A generic type allows you to provide an optional `type parameter` so that a function understands the type of the data it is handling.
21+
D1 Worker Bindings API is fully-typed via the runtime types generated by running [`wrangler types`](/workers/languages/typescript/#typescript) package, and also supports [generic types](https://www.typescriptlang.org/docs/handbook/2/generics.html#generic-types) as part of its TypeScript API. A generic type allows you to provide an optional `type parameter` so that a function understands the type of the data it is handling.
2222

2323
When using the query statement methods [`D1PreparedStatement::run`](/d1/worker-api/prepared-statements/#run), [`D1PreparedStatement::raw`](/d1/worker-api/prepared-statements/#raw) and [`D1PreparedStatement::first`](/d1/worker-api/prepared-statements/#first), you can provide a type representing each database row. D1's API will [return the result object](/d1/worker-api/return-object/#d1result) with the correct type.
2424

src/content/docs/vectorize/reference/client-api.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,4 @@ Refer to the [bindings documentation](/workers/wrangler/configuration/#vectorize
218218

219219
## TypeScript Types
220220

221-
New Workers projects created via `npm create cloudflare@latest` automatically include the relevant TypeScript types for Vectorize.
222-
223-
If you have an older project, or a non-Workers projects looking to use Vectorize's [REST API](https://developers.cloudflare.com/api/resources/vectorize/subresources/indexes/methods/list/) in a TypeScript project, you should ensure you have a compatibility date later than `2023-09-22` and that you have generated types by running [`wrangler types`](/workers/languages/typescript/#generate-types).
221+
<Render file="wrangler-typegen" />

src/content/docs/workers/testing/vitest-integration/migration-guides/migrate-from-miniflare-2.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ If you are using TypeScript, update your `tsconfig.json` to include the correct
6464
"compilerOptions": {
6565
...,
6666
"types": [
67-
"@cloudflare/workers-types/experimental"
67+
...
6868
- "vitest-environment-miniflare/globals"
6969
+ "@cloudflare/vitest-pool-workers"
7070
]

src/content/docs/workers/vite-plugin/tutorial.mdx

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,37 @@ This tutorial, however, will show you how to go a step further and add an API Wo
103103

104104
## Add an API Worker
105105

106+
### Add to your Worker configuration
107+
108+
<WranglerConfig>
109+
110+
```toml
111+
name = "cloudflare-vite-tutorial"
112+
compatibility_date = "2025-04-03"
113+
assets = { not_found_handling = "single-page-application" }
114+
main = "./worker/index.ts"
115+
```
116+
117+
</WranglerConfig>
118+
119+
The `main` field specifies the entry file for your Worker code.
120+
106121
### Configure TypeScript for your Worker code
107122

108-
<PackageManagers type="add" pkg="@cloudflare/workers-types" dev />
123+
<Render file="wrangler-typegen" />
124+
125+
Then create a `tsconfig.worker.json` file in the root of your project with the following content:
109126

110127
```jsonc title="tsconfig.worker.json"
111128
{
112129
"extends": "./tsconfig.node.json",
113130
"compilerOptions": {
114131
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.worker.tsbuildinfo",
115-
"types": ["@cloudflare/workers-types/2023-07-01", "vite/client"],
132+
"types": [
133+
// output of `wrangler types`
134+
"./worker-configuration.d.ts",
135+
"vite/client",
136+
],
116137
},
117138
"include": ["worker"],
118139
}
@@ -129,28 +150,9 @@ This tutorial, however, will show you how to go a step further and add an API Wo
129150
}
130151
```
131152

132-
### Add to your Worker configuration
133-
134-
<WranglerConfig>
135-
136-
```toml
137-
name = "cloudflare-vite-tutorial"
138-
compatibility_date = "2025-04-03"
139-
assets = { not_found_handling = "single-page-application" }
140-
main = "./worker/index.ts"
141-
```
142-
143-
</WranglerConfig>
144-
145-
The `main` field specifies the entry file for your Worker code.
146-
147153
### Add your API Worker
148154

149155
```ts title="worker/index.ts"
150-
interface Env {
151-
ASSETS: Fetcher;
152-
}
153-
154156
export default {
155157
fetch(request, env) {
156158
const url = new URL(request.url);

src/content/docs/workflows/build/workers-api.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,19 @@ script_name = "billing-worker"
212212

213213
</WranglerConfig>
214214

215+
<Render file="wrangler-typegen" />
216+
215217
## Workflow
216218

217219
:::note
218220

219-
Ensure you have a compatibility date `2024-10-22` or later installed when binding to Workflows from within a Workers project. If you are using TypeScript, ensure you have generated types by running [`wrangler types`](/workers/languages/typescript/#generate-types).
221+
Ensure you have a compatibility date `2024-10-22` or later installed when binding to Workflows from within a Workers project.
220222

221223
:::
222224

223225
The `Workflow` type provides methods that allow you to create, inspect the status, and manage running Workflow instances from within a Worker script.
224226

225-
```ts
227+
```ts title="./worker-configuration.d.ts"
226228
interface Env {
227229
// The 'MY_WORKFLOW' variable should match the "binding" value set in the Wrangler config file
228230
MY_WORKFLOW: Workflow;

src/content/docs/workflows/examples/send-invoices.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,4 @@ name = "SEND_EMAIL"
219219

220220
</WranglerConfig>
221221

222-
Also ensure you have generated types by running [`wrangler types`](/workers/languages/typescript/#generate-types).
222+
<Render file="wrangler-typegen" />
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
If you're using TypeScript, run [`wrangler types`](/workers/wrangler/commands/#types) whenever you modify your Wrangler configuration file. This generates types for the `env` object based on your bindings, as well as [runtime types](/workers/languages/typescript/).

0 commit comments

Comments
 (0)