openBrowser()
自 v3.0 起可用 - 属于 @remotion/renderer 包的一部分.
🌐 Available since v3.0 - Part of the @remotion/renderer package.
打开一个 Chrome 或 Chromium 浏览器实例。通过在 renderFrames()、renderStill()、renderMedia() 和 getCompositions() 调用之间重用同一个实例,你可以节省时间,因为不需要为每次调用都打开和关闭浏览器。
🌐 Opens a Chrome or Chromium browser instance. By reusing an instance across renderFrames(), renderStill(), renderMedia() and getCompositions() calls, you can save time by not opening and closing browsers for each call.
const openBrowser: (
browser: Browser,
options: {
shouldDumpIo?: boolean;
browserExecutable?: string | null;
chromiumOptions?: ChromiumOptions;
},
) => Promise<puppeteer.Browser>;参数
🌐 Arguments
browser
目前唯一有效的选项是 "chrome"。此字段保留以兼容将来的其他浏览器。
🌐 Currently the only valid option is "chrome". This field is reserved for future compatibility with other browsers.
options?
一个包含以下一个或多个选项的对象:
🌐 An object containing one or more of the following options:
shouldDumpIo?
shouldDumpIo?自 v4.0.189 起已弃用,计划在 v5.0 中移除。
🌐 Deprecated since v4.0.189, scheduled for removal in v5.0.
如果设置为 true,日志和其他浏览器诊断信息将被打印到标准输出。此设置对于调试很有用。
将在 5.0 中移除: 请改用 logLevel。
🌐 If set to true, logs and other browser diagnostics are being printed to standard output. This setting is useful for debugging.
Will be removed in 5.0: Use logLevel instead.
logLevel?v4.0.189
One of trace, verbose, info, warn, error.Determines how much info is being logged to the console.
Default
info.
browserExecutable?
一个字符串,定义应使用的浏览器可执行文件在磁盘上的绝对路径。默认情况下,Remotion 会尝试自动检测它,如果不可用,将下载一个。如果定义了 puppeteerInstance,它将优先于 browserExecutable。
🌐 A string defining the absolute path on disk of the browser executable that should be used. By default Remotion will try to detect it automatically and download one if none is available. If puppeteerInstance is defined, it will take precedence over browserExecutable.
chromiumOptions?
允许你设置某些 Chromium / Google Chrome 标志。见:Chromium 标志。
🌐 Allows you to set certain Chromium / Google Chrome flags. See: Chromium flags.
Chromium 标志需要在浏览器启动时设置。如果你将一个实例传递给像 renderMedia() 这样的 SSR API,该 API 的 chromiumOptions 选项将不起作用,而是会使用传递给 openBrowser() 的标志。
forceDeviceScaleFactor?
设置一个缩放。如果你计划使用缩放,你在打开浏览器时就需要设置它。
🌐 Set a scale. If you plan to use scaling, you already need to set it when opening the browser.
onBrowserDownload?v4.0.137
Gets called when no compatible local browser is detected on the system and this API needs to download a browser. Return a callback to observe progress. See here for how to use this option.
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.
关闭浏览器
🌐 Closing the browser
使用 close() 方法清理你不再使用的浏览器:
🌐 Use the close() method to cleanup a browser you are not using anymore:
const browser = await openBrowser('chrome');
browser.close({silent: true});如果已经关闭或操作被中断,将抛出错误。
将 silent 选项设置为 true 将在不生成错误的情况下关闭浏览器。
🌐 If already closed or an operation is interrupted, an error is thrown.
Setting the silent option to true will close the browser without generating an error.
兼容性
🌐 Compatibility
| Browsers | Servers | Environments | |||||||
|---|---|---|---|---|---|---|---|---|---|
Chrome | Firefox | Safari | Node.js | Bun | Serverless Functions | ||||
另请参阅
🌐 See also