我在使用完整 Chrome 可执行文件(不是默认 Chromium)运行的 Puppeteer 作业中使用外部资源时遇到问题。任何帮助将不胜感激!
例如,如果我加载带有公共 URL 的视频,即使我在浏览器中手动点击它也能正常工作,但它会失败。
const videoElement = document.createElement('video');
videoElement.src = src;
videoElement.onloadedmetadata = function() {
console.log(videoElement.duration);
};
Run Code Online (Sandbox Code Playgroud)
这是我的 Puppeteer 电话:
(async () => {
const browser = await puppeteer.launch({
args: [
'--remote-debugging-port=9222',
'--autoplay-policy=no-user-gesture-required',
'--allow-insecure-localhost',
'--proxy-server=http://localhost:9000',
'--proxy-bypass-list=""',
'--no-sandbox',
'--disable-setuid-sandbox',
],
executablePath:
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
});
const page = await browser.newPage();
logConsole(page);
await page.goto(`http://${hostname}/${path}`, {
waitUntil: 'networkidle2',
});
await page.waitForSelector('#job-complete');
console.log('Job complete!');
await browser.close();
})();
Run Code Online (Sandbox Code Playgroud)
与许多 Puppeteer 示例不同,这里的问题不是我的测试等待的时间不够长。资源几乎无法立即加载/返回空响应。
它似乎也不是身份验证问题 - 我可以很好地访问我自己的服务器。
虽然我没有在 https 上运行,但我直接在浏览器中尝试的 URL 在没有 SSL …