Why does it fail when using using the page instance (not in the same scope as the newPage) in a function ? Appreciate help and explanation.
'use strict'; // see strict mode
var url ='http://example.com';
const puppeteer = require('puppeteer');
(async() => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
func1(page);
browser.close();
})();
async func1(page) {
console.log(page); // output ok
await page.goto(url, {waitUntil: 'network idle'}); // failed!
}
You don't await
func1, sobrowser.closeruns beforepage.gotofinishes.'network idle'should also be'networkidle'with no space.