Skip to content

Commit bdca6cd

Browse files
authored
Merge pull request #84 from cloudflare/BRAPI-609
Add recording option to acquire
2 parents d967b25 + fedc899 commit bdca6cd

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

packages/playwright-cloudflare/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export interface LimitsResponse {
8686
*/
8787
export interface WorkersLaunchOptions {
8888
keep_alive?: number; // milliseconds to keep browser alive even if it has no activity (from 10_000ms to 600_000ms, default is 60_000)
89+
recording?: boolean;
8990
}
9091

9192
/**

packages/playwright-cloudflare/src/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,21 @@ export async function launch(endpoint: BrowserEndpoint, launchOptions?: WorkersL
145145

146146
export async function acquire(endpoint: BrowserEndpoint, options?: WorkersLaunchOptions): Promise<AcquireResponse> {
147147
options = { ...extractOptions(endpoint), ...options };
148-
let acquireUrl = `${HTTP_FAKE_HOST}/v1/acquire`;
148+
149+
// add options to acquire endpoint as query parameters
150+
const searchParams = new URLSearchParams();
149151
if (options?.keep_alive)
150-
acquireUrl = `${acquireUrl}?keep_alive=${options.keep_alive}`;
152+
searchParams.set("keep_alive", options.keep_alive.toString());
153+
if (options?.recording)
154+
searchParams.set("recording", options.recording.toString());
151155

156+
const acquireUrl = `${HTTP_FAKE_HOST}/v1/acquire?${searchParams.toString()}`;
152157
const res = await getBrowserBinding(endpoint).fetch(acquireUrl);
153158
const status = res.status;
154159
const text = await res.text();
155160
if (status !== 200) {
156161
throw new Error(
157-
`Unable to create new browser: code: ${status}: message: ${text}`
162+
`Unable to create new browser: code: ${status}: message: ${text}`
158163
);
159164
}
160165
// Got a 200, so response text is actually an AcquireResponse

0 commit comments

Comments
 (0)