|
| 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 { RequestOptions } from '../../internal/request-options'; |
| 6 | +import { path } from '../../internal/utils/path'; |
| 7 | + |
| 8 | +export class Playwright extends APIResource { |
| 9 | + /** |
| 10 | + * Execute arbitrary Playwright code in a fresh execution context against the |
| 11 | + * browser. The code runs in the same VM as the browser, minimizing latency and |
| 12 | + * maximizing throughput. It has access to 'page', 'context', and 'browser' |
| 13 | + * variables. It can `return` a value, and this value is returned in the response. |
| 14 | + * |
| 15 | + * @example |
| 16 | + * ```ts |
| 17 | + * const response = await client.browsers.playwright.execute( |
| 18 | + * 'id', |
| 19 | + * { code: 'code' }, |
| 20 | + * ); |
| 21 | + * ``` |
| 22 | + */ |
| 23 | + execute( |
| 24 | + id: string, |
| 25 | + body: PlaywrightExecuteParams, |
| 26 | + options?: RequestOptions, |
| 27 | + ): APIPromise<PlaywrightExecuteResponse> { |
| 28 | + return this._client.post(path`/browsers/${id}/playwright/execute`, { body, ...options }); |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +/** |
| 33 | + * Result of Playwright code execution |
| 34 | + */ |
| 35 | +export interface PlaywrightExecuteResponse { |
| 36 | + /** |
| 37 | + * Whether the code executed successfully |
| 38 | + */ |
| 39 | + success: boolean; |
| 40 | + |
| 41 | + /** |
| 42 | + * Error message if execution failed |
| 43 | + */ |
| 44 | + error?: string; |
| 45 | + |
| 46 | + /** |
| 47 | + * The value returned by the code (if any) |
| 48 | + */ |
| 49 | + result?: unknown; |
| 50 | + |
| 51 | + /** |
| 52 | + * Standard error from the execution |
| 53 | + */ |
| 54 | + stderr?: string; |
| 55 | + |
| 56 | + /** |
| 57 | + * Standard output from the execution |
| 58 | + */ |
| 59 | + stdout?: string; |
| 60 | +} |
| 61 | + |
| 62 | +export interface PlaywrightExecuteParams { |
| 63 | + /** |
| 64 | + * TypeScript/JavaScript code to execute. The code has access to 'page', 'context', |
| 65 | + * and 'browser' variables. It runs within a function, so you can use a return |
| 66 | + * statement at the end to return a value. This value is returned as the `result` |
| 67 | + * property in the response. Example: "await page.goto('https://example.com'); |
| 68 | + * return await page.title();" |
| 69 | + */ |
| 70 | + code: string; |
| 71 | + |
| 72 | + /** |
| 73 | + * Maximum execution time in seconds. Default is 60. |
| 74 | + */ |
| 75 | + timeout_sec?: number; |
| 76 | +} |
| 77 | + |
| 78 | +export declare namespace Playwright { |
| 79 | + export { |
| 80 | + type PlaywrightExecuteResponse as PlaywrightExecuteResponse, |
| 81 | + type PlaywrightExecuteParams as PlaywrightExecuteParams, |
| 82 | + }; |
| 83 | +} |
0 commit comments