Skip to main content

确保浏览器()v4.0.137

🌐 ensureBrowser()v4.0.137

确保浏览器已在本地安装,以便可以执行 Remotion 渲染。

🌐 Ensures a browser is locally installed so a Remotion render can be executed.

Simple usage
import {ensureBrowser} from '@remotion/renderer'; await ensureBrowser();
Setting a specific Chrome version and listening to progress
import {ensureBrowser} from '@remotion/renderer'; await ensureBrowser({ onBrowserDownload: () => { console.log('Downloading browser'); return { version: '144.0.7559.20', 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?

传递一个浏览器可执行文件的路径,你希望使用它而不是下载。
如果该路径不存在,该函数将抛出异常。
将相同的路径传递给支持 browserExecutable 选项的任何其他 API。

🌐 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

指定应使用的特定版本的 Chrome,并钩子到下载进度。
请参阅下面的示例了解函数签名。

🌐 Specify a specific version of Chrome that should be used and hook into the download progress.
See the example below for the function signature.

init.ts
import {ensureBrowser, OnBrowserDownload, DownloadBrowserProgressFn} from '@remotion/renderer'; const onProgress: DownloadBrowserProgressFn = ({percent, downloadedBytes, totalSizeInBytes}) => { console.log(`${Math.round(percent * 100)}% downloaded`); }; const onBrowserDownload: OnBrowserDownload = () => { console.log('Downloading browser'); return { // Pass `null` to use Remotion's recommendation. version: '144.0.7559.20', onProgress, }; }; await ensureBrowser({ onBrowserDownload, });

返回值

🌐 Return value

没有值的承诺。

🌐 A promise with no value.

兼容性

🌐 Compatibility

BrowsersServersEnvironments
Chrome
Firefox
Safari
Node.js
Bun
Serverless Functions

另请参阅

🌐 See also