Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"deploy": "wrangler deploy"
},
"devDependencies": {
"@cloudflare/playwright": "^0.0.9",
"@cloudflare/playwright": "^0.0.10",
"typescript": "^5.8.3",
"wrangler": "^4.13.0"
}
Expand Down
201 changes: 201 additions & 0 deletions packages/playwright-cloudflare/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,206 @@ declare module './types/types' {
}
}

/**
* @public
*/
export type Location =
| 'AF'
| 'AL'
| 'DZ'
| 'AD'
| 'AO'
| 'AG'
| 'AR'
| 'AM'
| 'AU'
| 'AT'
| 'AZ'
| 'BH'
| 'BD'
| 'BB'
| 'BY'
| 'BE'
| 'BZ'
| 'BJ'
| 'BM'
| 'BT'
| 'BO'
| 'BA'
| 'BW'
| 'BR'
| 'BN'
| 'BG'
| 'BF'
| 'BI'
| 'KH'
| 'CM'
| 'CA'
| 'CV'
| 'KY'
| 'CF'
| 'TD'
| 'CL'
| 'CN'
| 'CO'
| 'KM'
| 'CG'
| 'CR'
| 'CI'
| 'HR'
| 'CU'
| 'CY'
| 'CZ'
| 'CD'
| 'DK'
| 'DJ'
| 'DM'
| 'DO'
| 'EC'
| 'EG'
| 'SV'
| 'GQ'
| 'ER'
| 'EE'
| 'SZ'
| 'ET'
| 'FJ'
| 'FI'
| 'FR'
| 'GA'
| 'GE'
| 'DE'
| 'GH'
| 'GR'
| 'GL'
| 'GD'
| 'GT'
| 'GN'
| 'GW'
| 'GY'
| 'HT'
| 'HN'
| 'HU'
| 'IS'
| 'IN'
| 'ID'
| 'IR'
| 'IQ'
| 'IE'
| 'IL'
| 'IT'
| 'JM'
| 'JP'
| 'JO'
| 'KZ'
| 'KE'
| 'KI'
| 'KW'
| 'KG'
| 'LA'
| 'LV'
| 'LB'
| 'LS'
| 'LR'
| 'LY'
| 'LI'
| 'LT'
| 'LU'
| 'MO'
| 'MG'
| 'MW'
| 'MY'
| 'MV'
| 'ML'
| 'MR'
| 'MU'
| 'MX'
| 'FM'
| 'MD'
| 'MC'
| 'MN'
| 'MS'
| 'MA'
| 'MZ'
| 'MM'
| 'NA'
| 'NR'
| 'NP'
| 'NL'
| 'NZ'
| 'NI'
| 'NE'
| 'NG'
| 'KP'
| 'MK'
| 'NO'
| 'OM'
| 'PK'
| 'PS'
| 'PA'
| 'PG'
| 'PY'
| 'PE'
| 'PH'
| 'PL'
| 'PT'
| 'QA'
| 'RO'
| 'RU'
| 'RW'
| 'SH'
| 'KN'
| 'LC'
| 'VC'
| 'WS'
| 'SM'
| 'ST'
| 'SA'
| 'SN'
| 'RS'
| 'SC'
| 'SL'
| 'SK'
| 'SI'
| 'SB'
| 'SO'
| 'ZA'
| 'KR'
| 'SS'
| 'ES'
| 'LK'
| 'SD'
| 'SR'
| 'SE'
| 'CH'
| 'SY'
| 'TW'
| 'TJ'
| 'TZ'
| 'TH'
| 'BS'
| 'GM'
| 'TL'
| 'TG'
| 'TO'
| 'TT'
| 'TN'
| 'TR'
| 'TM'
| 'UG'
| 'UA'
| 'AE'
| 'GB'
| 'US'
| 'UY'
| 'UZ'
| 'VU'
| 'VE'
| 'VN'
| 'YE'
| 'ZM'
| 'ZW';

/**
* @public
*/
Expand Down Expand Up @@ -86,6 +286,7 @@ export interface LimitsResponse {
*/
export interface WorkersLaunchOptions {
keep_alive?: number; // milliseconds to keep browser alive even if it has no activity (from 10_000ms to 600_000ms, default is 60_000)
location?: Location;
}

// Extracts the keys whose values match a specified type `ValueType`
Expand Down
8 changes: 5 additions & 3 deletions packages/playwright-cloudflare/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import './patch';
import './polyfills/process';

import { createInProcessPlaywright } from 'playwright-core/lib/inProcessFactory';
import { kBrowserCloseMessageId } from 'playwright-core/lib/server/chromium/crConnection';
Expand Down Expand Up @@ -133,9 +133,11 @@ export async function launch(endpoint: BrowserEndpoint, launchOptions?: WorkersL

export async function acquire(endpoint: BrowserEndpoint, options?: WorkersLaunchOptions): Promise<AcquireResponse> {
options = { ...extractOptions(endpoint), ...options };
let acquireUrl = `${HTTP_FAKE_HOST}/v1/acquire`;
const acquireUrl = new URL(`${HTTP_FAKE_HOST}/v1/acquire`);
if (options?.keep_alive)
acquireUrl = `${acquireUrl}?keep_alive=${options.keep_alive}`;
acquireUrl.searchParams.append('keep_alive', String(options.keep_alive));
if (options?.location)
acquireUrl.searchParams.set('location', options.location);

const res = await getBrowserBinding(endpoint).fetch(acquireUrl);
const status = res.status;
Expand Down
2 changes: 2 additions & 0 deletions packages/playwright-cloudflare/src/internal.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import './polyfills/process';

import fs from 'fs';

import { asLocator, currentZone, isString, ManualPromise, setTimeOrigin, timeOrigin } from 'playwright-core/lib/utils';
Expand Down
3 changes: 0 additions & 3 deletions packages/playwright-cloudflare/src/patch.ts

This file was deleted.

36 changes: 36 additions & 0 deletions packages/playwright-cloudflare/src/polyfills/process.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
if (!process || !process.env)
throw new Error('process is not defined, ensure cloudflare worker has nodejs_compat compatibility flag enabled');

const noop = () => {};

const polyfillProcess = {
versions: {
node: '22.15.0',
},
version: 'v22.15.0',
argv: [],
stdout: {
isTTY: false,
},
on: noop,
addListener: noop,
once: noop,
off: noop,
removeListener: noop,
removeAllListeners: noop,
emit: noop,
prependListener: noop,
prependOnceListener: noop,
};

function merge(target: any, source: any) {
for (const key in source) {
if (typeof source[key] === 'object' && !Array.isArray(source[key]))
target[key] = merge(target[key] || {}, source[key]);
else if (!target[key])
target[key] = source[key];
}
return target;
}

merge(process, polyfillProcess);
2 changes: 2 additions & 0 deletions packages/playwright-cloudflare/src/test.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
import './polyfills/process';

export * from './index';
export { expect, mergeExpects } from 'playwright/lib/matchers/expect';
31 changes: 1 addition & 30 deletions packages/playwright-cloudflare/utils/generate_worker_tests.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs from 'fs';
import path from "path";
import { fileURLToPath } from "url";
import { build } from "vite";
Expand Down Expand Up @@ -167,35 +166,7 @@ ${[...testFiles, ...cloudflareTestFiles].map(file => `import ${JSON.stringify(fi
chunkFileNames: '[name].js',
},
external: [
'node:async_hooks',
'node:assert',
'node:buffer',
'node:child_process',
'node:constants',
'node:crypto',
'node:dns',
'node:domain',
'node:events',
'node:http',
'node:http2',
'node:https',
'node:inspector',
'node:module',
'node:net',
'node:os',
'node:path',
'node:querystring',
'node:process',
'node:readline',
'node:stream',
'node:string_decoder',
'node:timers',
'node:tls',
'node:url',
'node:util',
'node:vm',
'node:zlib',

/^node:/,
'cloudflare:workers',
/^@cloudflare\/playwright.*/,
]
Expand Down
26 changes: 1 addition & 25 deletions packages/playwright-cloudflare/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,31 +105,7 @@ export default defineConfig({
},
],
external: [
'node:async_hooks',
'node:assert',
'node:browser',
'node:buffer',
'node:child_process',
'node:constants',
'node:crypto',
'node:dns',
'node:events',
'node:http',
'node:http2',
'node:https',
'node:inspector',
'node:module',
'node:net',
'node:os',
'node:path',
'node:process',
'node:readline',
'node:stream',
'node:timers',
'node:tls',
'node:url',
'node:util',
'node:zlib',
/^node:/,
'cloudflare:workers',
]
},
Expand Down