ensureBrowser()v4.0.137
Ensures a browser is locally installed so a Remotion render can be executed.
Simple usageimport {ensureBrowser } from '@remotion/renderer'; awaitensureBrowser ();
Setting a specific Chrome version and listening to progressimport {ensureBrowser } from '@remotion/renderer'; awaitensureBrowser ({onBrowserDownload : () => {console .log ('Downloading browser'); return {version : '157.0.8080.0',onProgress : ({percent }) => {console .log (`${Math .round (percent * 100)}% downloaded`); }, }; }, });
API
An object with the following properties, all of which are optional:
chromeMode?v4.0.248
One of headless-shell, chrome-for-testing. Default headless-shell. Use chrome-for-testing to take advantage of GPU drivers on Linux.
browserExecutable?
Pass a path to a browser executable that you want to use instead of downloading.
If the path does not exist, this function will throw.
Pass the same path to any other API that supports the browserExecutable option.
logLevel?
One of trace, verbose, info, warn, error.Determines how much info is being logged to the console.
Default
info.
onBrowserDownload?
Hook into the browser download progress, and optionally specify which Chrome version to use.
See the example below for the function signature.
Most projects don't need to pass onBrowserDownload, or only use it to show the download progress and return version: null. Remotion then uses its default Chrome Headless Shell build, which includes optimizations such as shared-memory capture.
Only return a version if your environment needs a specific Chrome build, for example one that contains a fix for your platform. Custom versions are stock builds from Google without Remotion's optimizations.
ensureBrowser() calls this function every time and uses the version you return, downloading it if it is not installed yet. onProgress is only called if a download happens.
Other APIs that accept onBrowserDownload, such as renderMedia() and selectComposition(), use Remotion's default version if it is installed and only call onBrowserDownload otherwise. To use a custom version in all APIs, pass the path returned by ensureBrowser() as browserExecutable:
render.tsconstbrowser = awaitensureBrowser ({onBrowserDownload : () => ({version : '144.0.7559.20',onProgress : () =>undefined , }), }); if (browser .type !== 'local-puppeteer-browser') { throw newError ('Expected a downloaded browser'); } constcomposition = awaitselectComposition ({serveUrl ,id : 'MyComp',browserExecutable :browser .path , }); awaitrenderMedia ({composition ,serveUrl ,codec : 'h264',outputLocation : 'out.mp4',browserExecutable :browser .path , });
From v4.0.544, Remotion installs each version into its own folder, so installing one version does not delete another.
init.tsimport {ensureBrowser ,OnBrowserDownload ,DownloadBrowserProgressFn } from '@remotion/renderer'; constonProgress :DownloadBrowserProgressFn = ({percent ,downloadedBytes ,totalSizeInBytes }) => {console .log (`${Math .round (percent * 100)}% downloaded`); }; constonBrowserDownload :OnBrowserDownload = () => {console .log ('Downloading browser'); return { // Pass `null` to use Remotion's recommendation.version : '157.0.8080.0',onProgress , }; }; awaitensureBrowser ({onBrowserDownload , });
Return value
A promise resolving to an object describing the browser that is now available. Its type field is "user-defined-path" if a browserExecutable was passed, otherwise "local-puppeteer-browser". Both include the path of the executable.
Compatibility
| Browsers | Servers | Environments | |||||||
|---|---|---|---|---|---|---|---|---|---|
Chrome | Firefox | Safari | Node.js | Bun | Serverless Functions | ||||