我正在使用最新版本的 Puppeteer,以及 Chromium 80,并尝试在 Chrome headless 中从页面录制视频,已经打开了所有这些标志:
{
headless: true,
devtools: false,
args: [
'--no-sandbox',
'--allow-insecure-localhost',
'--enable-usermedia-screen-capturing',
'--use-fake-ui-for-media-stream', // In headless: false it will capture display rather than tab and in headless: true doesn't work
'--auto-select-desktop-capture-source=[RECORD]', //[RECORD] is the title of my localhost page trying to screen capture
'--remote-debugging-port=9222',
'--window-size=1440,900',
],
ignoreDefaultArgs: [
'--mute-audio',
'--disable-media-session-api',
]
}
在 Windows 上,如果
headless : false
,它将捕获 Chrome 标签(有时会崩溃)。但是,如果headless : true
,即使在 Windows 上,它也显示为不支持
。如果打开了
--use-fake-ui-for-media-stream
标志,则情况就另当别论,无论headless
是真还是假,它都会捕获我的其中一个显示器。现在我想在我的 Linux 服务器上使用它,因为那里没有显示器,我只希望 Chrome 的
headless : true
能够捕获我的 Chrome 标签。我知道它可以做到这一点,因为在 DevTools 中,我可以看到它以headless : true
模式显示屏幕。如果它在 DevTools 中创建了一个显示器,那么它必须能够在屏幕捕捉时创建显示器。我想,在 Puppeteer 上必须打开其他标志,才能允许它这样做。我正在使用navigator.mediaDevices.getDisplayMedia
来获取屏幕数据。我还尝试过这个视频配置,但它没有成功(崩溃),显然只适用于扩展程序,我需要从后台获取源 ID。
screenStream = await navigator.mediaDevices.getDisplayMedia({
video: {
//mandatory: {
// chromeMediaSource: 'tab', // Not using this!
//}
},
audio: false
});
有没有人知道在Puppeteer中还应该考虑哪些标志?
请注意,我不想在我的Chrome headless中使用xvfb和Selenium(WebDrive)或任何扩展程序。