|
| 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 | +} |
0 commit comments