Skip to content

Commit f4f2e51

Browse files
committed
docs(renderer): document closeBrowser() and fix the usage example
The shared headless browser stays open after a render, so a script using the renderer API never exits unless it calls closeBrowser(). Say so, and show it in the usage example. The example also imported bundle from @rendiv/renderer (it lives in @rendiv/bundler) and passed compositionId, which renderMedia does not accept; use selectComposition() and the composition option instead.
1 parent 6d6aca2 commit f4f2e51

1 file changed

Lines changed: 27 additions & 14 deletions

File tree

‎docs/packages/renderer.md‎

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,51 @@ Server-side rendering API for Node.js and Bun. Captures frames via headless Chro
55
## Installation
66

77
```bash
8-
npm install @rendiv/renderer
8+
npm install @rendiv/renderer @rendiv/bundler
99
```
1010

1111
## Usage
1212

1313
```ts
14-
import { renderMedia, bundle } from '@rendiv/renderer';
14+
import { bundle } from '@rendiv/bundler';
15+
import { renderMedia, selectComposition, closeBrowser } from '@rendiv/renderer';
1516

1617
// 1. Bundle your compositions
1718
const bundled = await bundle({ entryPoint: 'src/index.tsx' });
1819

19-
// 2. Render to video
20-
await renderMedia({
21-
serveUrl: bundled,
22-
compositionId: 'MyVideo',
23-
codec: 'mp4',
24-
outputLocation: 'out/video.mp4',
25-
concurrency: 4,
26-
onProgress: ({ progress }) => {
27-
console.log(`${Math.round(progress * 100)}%`);
28-
},
29-
});
20+
try {
21+
// 2. Look up the composition
22+
const composition = await selectComposition(bundled, 'MyVideo');
23+
24+
// 3. Render to video
25+
await renderMedia({
26+
serveUrl: bundled,
27+
composition,
28+
codec: 'mp4',
29+
outputLocation: 'out/video.mp4',
30+
concurrency: 4,
31+
onProgress: ({ progress }) => {
32+
console.log(`${Math.round(progress * 100)}%`);
33+
},
34+
});
35+
} finally {
36+
// 4. Close the shared headless browser so the process can exit
37+
await closeBrowser();
38+
}
3039
```
3140

41+
## Closing the browser
42+
43+
`renderMedia`, `renderFrames`, `renderStill` and `getCompositions` share one headless Chromium instance, which stays open between calls so later renders start faster. The renderer does not close it for you: call `closeBrowser()` when you are done rendering, or the Node.js process will not exit.
44+
3245
## renderMedia
3346

3447
Render a composition to a video file.
3548

3649
| Option | Type | Default | Description |
3750
|--------|------|---------|-------------|
3851
| `serveUrl` | `string` | required | URL or path to the bundled output |
39-
| `compositionId` | `string` | required | ID of the composition to render |
52+
| `composition` | `CompositionInfo` | required | The composition to render, from `selectComposition()` |
4053
| `codec` | `string` | `'mp4'` | Output codec (`'mp4'`, `'webm'`) |
4154
| `outputLocation` | `string` | required | Output file path |
4255
| `concurrency` | `number` | `4` | Number of parallel browser tabs |

0 commit comments

Comments
 (0)