Skip to content

Commit

Permalink
docs: document launch in browsers better (#13002)
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN authored Aug 26, 2024
1 parent 132a7ce commit 77895ce
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/browsers-api/browsers.launch.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ sidebar_label: launch

# launch() function

Launches a browser process according to [LaunchOptions](./browsers.launchoptions.md).

### Signature

```typescript
Expand Down
32 changes: 32 additions & 0 deletions docs/browsers-api/browsers.launchoptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ string\[\]

</td><td>

Additional arguments to pass to the executable when launching.

</td><td>

</td></tr>
Expand All @@ -64,8 +66,12 @@ boolean

</td><td>

Whether to spawn process in the [detached](https://nodejs.org/api/child_process.html#optionsdetached) mode.

</td><td>

`true` except on Windows.

</td></tr>
<tr><td>

Expand All @@ -81,8 +87,12 @@ boolean

</td><td>

If true, forwards the browser's process stdout and stderr to the Node's process stdout and stderr.

</td><td>

`false`.

</td></tr>
<tr><td>

Expand All @@ -98,6 +108,8 @@ Record&lt;string, string \| undefined&gt;

</td><td>

Environment variables to set for the browser process.

</td><td>

</td></tr>
Expand All @@ -113,6 +125,8 @@ string

</td><td>

Absolute path to the browser's executable.

</td><td>

</td></tr>
Expand All @@ -130,8 +144,12 @@ boolean

</td><td>

Handles SIGHUP in the Node process and tries to gracefully close the browser process.

</td><td>

`true`.

</td></tr>
<tr><td>

Expand All @@ -147,8 +165,12 @@ boolean

</td><td>

Handles SIGINT in the Node process and tries to kill the browser process.

</td><td>

`true`.

</td></tr>
<tr><td>

Expand All @@ -164,8 +186,12 @@ boolean

</td><td>

Handles SIGTERM in the Node process and tries to gracefully close the browser process.

</td><td>

`true`.

</td></tr>
<tr><td>

Expand All @@ -181,6 +207,8 @@ boolean

</td><td>

A callback to run after the browser process exits or before the process will be closed via the [Process.close()](./browsers.process.close.md) call (including when handling signals). The callback is only run once.

</td><td>

</td></tr>
Expand All @@ -198,7 +226,11 @@ boolean

</td><td>

Configures stdio streams to open two additional streams for automation over those streams instead of WebSocket.

</td><td>

`false`.

</td></tr>
</tbody></table>
2 changes: 2 additions & 0 deletions docs/browsers-api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ Returns a version comparator for the given browser that can be used to sort brow

</td><td>

Launches a browser process according to [LaunchOptions](./browsers.launchoptions.md).

</td></tr>
<tr><td>

Expand Down
50 changes: 50 additions & 0 deletions packages/browsers/src/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,69 @@ export function computeSystemExecutablePath(options: SystemOptions): string {
* @public
*/
export interface LaunchOptions {
/**
* Absolute path to the browser's executable.
*/
executablePath: string;
/**
* Configures stdio streams to open two additional streams for automation over
* those streams instead of WebSocket.
*
* @defaultValue `false`.
*/
pipe?: boolean;
/**
* If true, forwards the browser's process stdout and stderr to the Node's
* process stdout and stderr.
*
* @defaultValue `false`.
*/
dumpio?: boolean;
/**
* Additional arguments to pass to the executable when launching.
*/
args?: string[];
/**
* Environment variables to set for the browser process.
*/
env?: Record<string, string | undefined>;
/**
* Handles SIGINT in the Node process and tries to kill the browser process.
*
* @defaultValue `true`.
*/
handleSIGINT?: boolean;
/**
* Handles SIGTERM in the Node process and tries to gracefully close the browser
* process.
*
* @defaultValue `true`.
*/
handleSIGTERM?: boolean;
/**
* Handles SIGHUP in the Node process and tries to gracefully close the browser process.
*
* @defaultValue `true`.
*/
handleSIGHUP?: boolean;
/**
* Whether to spawn process in the {@link https://nodejs.org/api/child_process.html#optionsdetached | detached}
* mode.
*
* @defaultValue `true` except on Windows.
*/
detached?: boolean;
/**
* A callback to run after the browser process exits or before the process
* will be closed via the {@link Process.close} call (including when handling
* signals). The callback is only run once.
*/
onExit?: () => Promise<void>;
}

/**
* Launches a browser process according to {@link LaunchOptions}.
*
* @public
*/
export function launch(opts: LaunchOptions): Process {
Expand Down

0 comments on commit 77895ce

Please sign in to comment.