【发布时间】:2021-09-03 07:12:33
【问题描述】:
我使用Puppeteer来启动一个浏览器页面,如下:
const browser = await puppeteer.launch({
executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
headless: true,
devtools: true,
args: [
'--no-sandbox',
'--disable-web-security',
'--allow-file-access-from-files',
'--use-fake-ui-for-media-stream',
'--use-fake-device-for-media-stream',
'--disable-gpu'
]
});
const page = await browser.newPage()
await page.goto(`http://localhost:3001/hello.html`);
hello.html 页面效果很好,但是当我创建 Video 元素并读取 audioTracks 属性时,它返回 undefined。
但是,如果我直接在谷歌浏览器中使用相同的代码,而不是由 Puppeteer 启动,video.audioTracks 会正确返回。
const video = document.createElement('video')
console.log('tracks:', video.audioTracks) // should be tracks: AudioTrackList, but undefined in Puppeteer
这让我很困惑..希望有人能解释这种奇怪的行为。
谢谢..
【问题讨论】:
-
您能否展示网站代码的最小版本,该代码创建一个 Video 元素并读取 audioTracks 属性?您是否真的在某个时候将此元素放入 DOM 中?你是如何在 Puppeteer 中选择它的?
标签: javascript video puppeteer video-capture