背景
我正在本地应用程序中运行 Puppeteer,运行良好。当我将其移至生产 Debian 服务器时,它在
处超时page.goto(url)
函数。
示例
我在网上尝试了很多不同的建议。在下面的示例中,您将看到我尝试过的一些在线建议的选项。我单独尝试过这些方法,也尝试过以不同的方式组合这些方法。是的,我现在就是这么绝望。
const browser = await puppeteer.launch({
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--ignore-certificate-errors',
'--ignore-certificate-errors-spki-list',
'--user-data-dir']});
const page = await browser.newPage();
await page.goto(
`https://example.com/${template}?data=${JSON.stringify(req.body)}`, {waitUntil: 'networkidle0'}
);
page.goto(url) 在本地工作,但在服务器上运行时失败。
问题
为什么page.goto()
在服务器上失败,有什么解决办法吗?
最佳答案
page.setDefaultNavigationTimeout
是您的选择
const browser = await puppeteer.launch({
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--ignore-certificate-errors',
'--ignore-certificate-errors-spki-list',
'--user-data-dir']});
const page = await browser.newPage();
page.setDefaultNavigationTimeout(3600); // 1 hour
await page.goto(
`https://example.com/${template}?data=${JSON.stringify(req.body)}`, {waitUntil: 'networkidle2'}
);
关于javascript - Puppeteer 打开 URL 时超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50689868/