Reputation: 3
I'm running into a problem splitting a working solution using puppeteer into multiple modules for better readability and maintainability... reduced the code down to a few lines demonstrating the issue:
working version:
const puppeteer = require('puppeteer');
(async function main() {
try {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.goto('https://google.com')
await browser.close();
} catch (e) {
console.log(e);
}
})();
but as soon as I try to move the puppeteer initialization out of the main function like this:
const puppeteer = require('puppeteer');
async function f1() {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.new_page();
await page.goto('https://google.com')
await browser.close();
}
(async function main() {
try {
await f1();
} catch (e) {
console.log(e);
}
})();
I get this error message:
TypeError: browser.new_page is not a function
Upvotes: 0
Views: 1151
Reputation: 12926
It seems you have a typo, it should probably be browser.newPage
not browser.new_page
.
Upvotes: 1