Skip to content

Commit f2fc555

Browse files
feat: Expose named Playwright executors on the browser API
Stainless-Generated-From: 0ed78eb6ad96c088a44217b365927ac0dcbe0deb
1 parent 555d03d commit f2fc555

10 files changed

Lines changed: 399 additions & 93 deletions

File tree

‎.stats.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
configured_endpoints: 172
1+
configured_endpoints: 174

‎api.md‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,25 @@ Methods:
298298

299299
Types:
300300

301-
- <code><a href="./src/resources/browsers/playwright.ts">PlaywrightExecuteResponse</a></code>
301+
- <code><a href="./src/resources/browsers/playwright/playwright.ts">ExecutorLimitError</a></code>
302+
- <code><a href="./src/resources/browsers/playwright/playwright.ts">Tab</a></code>
303+
- <code><a href="./src/resources/browsers/playwright/playwright.ts">PlaywrightExecuteResponse</a></code>
302304

303305
Methods:
304306

305-
- <code title="post /browsers/{id_or_name}/playwright/execute">client.browsers.playwright.<a href="./src/resources/browsers/playwright.ts">execute</a>(idOrName, { ...params }) -> PlaywrightExecuteResponse</code>
307+
- <code title="post /browsers/{id_or_name}/playwright/execute">client.browsers.playwright.<a href="./src/resources/browsers/playwright/playwright.ts">execute</a>(idOrName, { ...params }) -> PlaywrightExecuteResponse</code>
308+
309+
### Executors
310+
311+
Types:
312+
313+
- <code><a href="./src/resources/browsers/playwright/executors.ts">Executor</a></code>
314+
- <code><a href="./src/resources/browsers/playwright/executors.ts">ExecutorList</a></code>
315+
316+
Methods:
317+
318+
- <code title="get /browsers/{id_or_name}/playwright/executors">client.browsers.playwright.executors.<a href="./src/resources/browsers/playwright/executors.ts">list</a>(idOrName) -> ExecutorList</code>
319+
- <code title="delete /browsers/{id_or_name}/playwright/executors/{name}">client.browsers.playwright.executors.<a href="./src/resources/browsers/playwright/executors.ts">delete</a>(name, { ...params }) -> void</code>
306320

307321
## Webmcp
308322

‎src/resources/browsers/browsers.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import {
2222
} from './computer';
2323
import * as LogsAPI from './logs';
2424
import { LogStreamParams, Logs } from './logs';
25-
import * as PlaywrightAPI from './playwright';
26-
import { Playwright, PlaywrightExecuteParams, PlaywrightExecuteResponse } from './playwright';
2725
import * as ProcessAPI from './process';
2826
import {
2927
Process,
@@ -128,6 +126,14 @@ import {
128126
FWriteFileParams,
129127
Fs,
130128
} from './fs/fs';
129+
import * as PlaywrightAPI from './playwright/playwright';
130+
import {
131+
ExecutorLimitError,
132+
Playwright,
133+
PlaywrightExecuteParams,
134+
PlaywrightExecuteResponse,
135+
Tab,
136+
} from './playwright/playwright';
131137
import * as WebmcpAPI from './webmcp/webmcp';
132138
import {
133139
CustomToolSource,
@@ -2121,6 +2127,8 @@ export declare namespace Browsers {
21212127

21222128
export {
21232129
Playwright as Playwright,
2130+
type ExecutorLimitError as ExecutorLimitError,
2131+
type Tab as Tab,
21242132
type PlaywrightExecuteResponse as PlaywrightExecuteResponse,
21252133
type PlaywrightExecuteParams as PlaywrightExecuteParams,
21262134
};

‎src/resources/browsers/index.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ export {
6767
type FWriteFileParams,
6868
} from './fs/index';
6969
export { Logs, type LogStreamParams } from './logs';
70-
export { Playwright, type PlaywrightExecuteResponse, type PlaywrightExecuteParams } from './playwright';
70+
export {
71+
Playwright,
72+
type ExecutorLimitError,
73+
type Tab,
74+
type PlaywrightExecuteResponse,
75+
type PlaywrightExecuteParams,
76+
} from './playwright/index';
7177
export {
7278
Process,
7379
type ProcessExecResponse,
Lines changed: 1 addition & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,3 @@
11
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3-
import { APIResource } from '../../core/resource';
4-
import { APIPromise } from '../../core/api-promise';
5-
import { RequestOptions } from '../../internal/request-options';
6-
import { path } from '../../internal/utils/path';
7-
8-
/**
9-
* Execute Playwright code against the browser instance.
10-
*/
11-
export class Playwright extends APIResource {
12-
/**
13-
* Execute arbitrary Playwright code in a fresh execution context against the
14-
* browser. The code runs in the same VM as the browser, minimizing latency and
15-
* maximizing throughput. It has access to 'page', 'context', 'browser', and
16-
* 'webmcp' variables. Use 'webmcp.listTools()' to discover browser-wide WebMCP
17-
* tools and 'webmcp.invokeTool(toolRef, input?, { timeoutSec? })' to invoke an
18-
* exact registration. It can `return` a value, and this value is returned in the
19-
* response.
20-
*
21-
* @example
22-
* ```ts
23-
* const response = await client.browsers.playwright.execute(
24-
* 'htzv5orfit78e1m2biiifpbv',
25-
* { code: 'code' },
26-
* );
27-
* ```
28-
*/
29-
execute(
30-
idOrName: string,
31-
body: PlaywrightExecuteParams,
32-
options?: RequestOptions,
33-
): APIPromise<PlaywrightExecuteResponse> {
34-
return this._client.post(path`/browsers/${idOrName}/playwright/execute`, { body, ...options });
35-
}
36-
}
37-
38-
/**
39-
* Result of Playwright code execution
40-
*/
41-
export interface PlaywrightExecuteResponse {
42-
/**
43-
* Whether the code executed successfully
44-
*/
45-
success: boolean;
46-
47-
/**
48-
* Error message if execution failed
49-
*/
50-
error?: string;
51-
52-
/**
53-
* The value returned by the code (if any)
54-
*/
55-
result?: unknown;
56-
57-
/**
58-
* Standard error from the execution
59-
*/
60-
stderr?: string;
61-
62-
/**
63-
* Standard output from the execution
64-
*/
65-
stdout?: string;
66-
}
67-
68-
export interface PlaywrightExecuteParams {
69-
/**
70-
* TypeScript/JavaScript code to execute. The code has access to 'page', 'context',
71-
* and 'browser' variables. It runs within a function, so you can use a return
72-
* statement at the end to return a value. This value is returned as the `result`
73-
* property in the response. Example: "await page.goto('https://example.com');
74-
* return await page.title();"
75-
*/
76-
code: string;
77-
78-
/**
79-
* Maximum execution time in seconds. Default is 60.
80-
*/
81-
timeout_sec?: number;
82-
}
83-
84-
export declare namespace Playwright {
85-
export {
86-
type PlaywrightExecuteResponse as PlaywrightExecuteResponse,
87-
type PlaywrightExecuteParams as PlaywrightExecuteParams,
88-
};
89-
}
3+
export * from './playwright/index';
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import { APIResource } from '../../../core/resource';
4+
import { APIPromise } from '../../../core/api-promise';
5+
import { buildHeaders } from '../../../internal/headers';
6+
import { RequestOptions } from '../../../internal/request-options';
7+
import { path } from '../../../internal/utils/path';
8+
9+
/**
10+
* Execute Playwright code against the browser instance and manage the executors it runs in.
11+
*/
12+
export class Executors extends APIResource {
13+
/**
14+
* Lists the default executor first, then the named executors created by POST
15+
* /browsers/{id_or_name}/playwright/execute. Each entry reports whether a call is
16+
* running on it and, for named executors, the target ID and URL of the tab it
17+
* owns. Returns 404 for a browser whose image predates executors.
18+
*
19+
* @example
20+
* ```ts
21+
* const executorList =
22+
* await client.browsers.playwright.executors.list(
23+
* 'htzv5orfit78e1m2biiifpbv',
24+
* );
25+
* ```
26+
*/
27+
list(idOrName: string, options?: RequestOptions): APIPromise<ExecutorList> {
28+
return this._client.get(path`/browsers/${idOrName}/playwright/executors`, options);
29+
}
30+
31+
/**
32+
* Stops the executor's process. A call running on it fails with an error saying
33+
* the executor was deleted. By default the executor's tab is closed too. The name
34+
* can be reused; the next call with it creates a new executor and tab.
35+
*
36+
* The default executor is restarted instead of removed: its process is stopped, a
37+
* call running on it fails with an error saying the executor was restarted, and
38+
* queued and later calls run on a new process. It owns no tab, so 'close_tab' has
39+
* no effect on it.
40+
*
41+
* @example
42+
* ```ts
43+
* await client.browsers.playwright.executors.delete(
44+
* 'checkout',
45+
* { id_or_name: 'htzv5orfit78e1m2biiifpbv' },
46+
* );
47+
* ```
48+
*/
49+
delete(name: string, params: ExecutorDeleteParams, options?: RequestOptions): APIPromise<void> {
50+
const { id_or_name, close_tab } = params;
51+
return this._client.delete(path`/browsers/${id_or_name}/playwright/executors/${name}`, {
52+
query: { close_tab },
53+
...options,
54+
headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
55+
});
56+
}
57+
}
58+
59+
/**
60+
* A Playwright executor on the browser
61+
*/
62+
export interface Executor {
63+
/**
64+
* Whether a call is running on the executor
65+
*/
66+
busy: boolean;
67+
68+
/**
69+
* When the executor was created
70+
*/
71+
created_at: string;
72+
73+
/**
74+
* When the most recent call on the executor started
75+
*/
76+
last_used_at: string;
77+
78+
/**
79+
* Name of a Playwright executor. Calls with the same name run in the same
80+
* executor, one at a time; the first call with a new name creates it. Calls on
81+
* different executors run concurrently. 'default' names the executor that runs
82+
* calls without a name.
83+
*/
84+
name: string;
85+
86+
/**
87+
* CDP page target ID of the executor's tab, once it has one. The default executor
88+
* owns no tab.
89+
*/
90+
target_id?: string;
91+
92+
/**
93+
* Current URL of the executor's tab, when it is open
94+
*/
95+
url?: string;
96+
}
97+
98+
/**
99+
* The default executor followed by the named executors
100+
*/
101+
export interface ExecutorList {
102+
executors: Array<Executor>;
103+
}
104+
105+
export interface ExecutorDeleteParams {
106+
/**
107+
* Path param: Browser session ID or name
108+
*/
109+
id_or_name: string;
110+
111+
/**
112+
* Query param: Close the executor's tab. Defaults to true.
113+
*/
114+
close_tab?: boolean;
115+
}
116+
117+
export declare namespace Executors {
118+
export {
119+
type Executor as Executor,
120+
type ExecutorList as ExecutorList,
121+
type ExecutorDeleteParams as ExecutorDeleteParams,
122+
};
123+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
export { Executors, type Executor, type ExecutorList, type ExecutorDeleteParams } from './executors';
4+
export {
5+
Playwright,
6+
type ExecutorLimitError,
7+
type Tab,
8+
type PlaywrightExecuteResponse,
9+
type PlaywrightExecuteParams,
10+
} from './playwright';

0 commit comments

Comments
 (0)