Posts

Showing posts with the label puppeteer

How can I set timeout option on every request in page.goto function

How can I set timeout option on every request in page.goto function I use puppeteer to scrab resources in a page. but one of the js request can not success because of connection timeout, and it will block the page.goto('url') function for a long time. I want to skip this js request and continue to request next. so i need to set timeout on every request, but not a total timeout option on page.goto function. Follow is my code test.js: const browser = await puppeteer.launch(); const page = await browser.newPage(); page.on('request', request => { console.log(request.url()) }) await page.goto(process.argv[2], {timeout: 10000}).then( () => { }, () => { console.log("timeout"); }); browser.close(); node test.js http://ipv6ready.wanwuyunlian.com:8080/ http://ipv6ready.wanwuyunlian.com:8080/ http://ipv6ready.wanwuyunlian.com:8080/js/bootstrap.min.js http://ipv6ready.wanwuyunlian.com:8080/js/echarts/echarts.min.js https://www.google-analytics.com/analyt...