'Puppeteer Navigation timeout of 30000 ms exceeded
I am trying to take a screenshot of the launched page using puppeteer but it threw error
TimeoutError: Navigation timeout of 30000 ms exceeded
This is my code
const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth')();
var Xvfb = require('xvfb');
var express = require('express');
var app = express();
StealthPlugin.onBrowser = () => { };
puppeteer.use(StealthPlugin);
// Required for virtual display in linux environment
var xvfb = new Xvfb({
displayNum: 99,
reuse: true,
silent: true,
xvfb_args: ['-dpi', 72, "-screen", "0", '1920x1080x24'],
});
xvfb.start((err) => { if (err) console.error(err) })
puppeteer.launch({
headless: false,
userDataDir: 'bot',
args: [
'--no-sandbox',
'--proxy-server="direct://"',
'--proxy-bypass-list=*',
'--start-fullscreen',
'--display=' + xvfb._display
]
}).then(async browser => {
console.log('Starting bot ...');
const page = await browser.newPage();
app.listen(3000, function(){
console.log('server is listening at port 3000')
})
app.get('/', async function (req, res) {
res.send('Test')
})
page.setDefaultNavigationTimeout(0)
await page.goto('https://www.facebook.com', { timeout: 0, waitUntil: 'networkidle2' });
// await page.screenshot({ path: 'example.png' });
});
It's working if I run in my windows localhost device but throwing error above when I run in ubuntu server. It wasn't able to listen to the port that I set too. It seem to be having error at the line await browser.newPage();
I know this issue has been posted many times but nothing works.
Solution 1:[1]
maybe your issue is website is not properly load you can try this code
const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth')();
var Xvfb = require('xvfb');
var express = require('express');
var app = express();
StealthPlugin.onBrowser = () => { };
puppeteer.use(StealthPlugin);
// Required for virtual display in linux environment
var xvfb = new Xvfb({
displayNum: 99,
reuse: true,
silent: true,
xvfb_args: ['-dpi', 72, "-screen", "0", '1920x1080x24'],
});
xvfb.start((err) => { if (err) console.error(err) })
puppeteer.launch({
headless: false,
userDataDir: 'bot',
args: [
'--no-sandbox',
'--proxy-server="direct://"',
'--proxy-bypass-list=*',
'--start-fullscreen',
'--display=' + xvfb._display
]
}).then(async browser => {
console.log('Starting bot ...');
const page = await browser.newPage();
app.listen(3000, function(){
console.log('server is listening at port 3000')
})
app.get('/', async function (req, res) {
res.send('Test')
})
await page.goto('https://www.facebook.com', { waitUntil: 'load' });
// await page.screenshot({ path: 'example.png' });
await page.waitForNavigation();
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | denial |
