Puppeteer log inside page.evaluate

Update for puppeteer 12, adapted from the current documentation: page.on(‘console’, async (msg) => { const msgArgs = msg.args(); for (let i = 0; i < msgArgs.length; ++i) { console.log(await msgArgs[i].jsonValue()); } }); await page.evaluate(() => console.log(‘hello’, 5)); await page.evaluate(() => console.log({ foo: ‘bar’ })); await page.evaluate(() => console.log([1, 2, 3, 4, 5])); Shows the following … Read more

Error: Failed to launch the browser process puppeteer

I had the same issue, I tried everything which is listed from the Puppeteer guide, none of them worked for me. What works for me was to download chromium manually sudo apt-get install chromium-browser. And then, tell Puppeteer where chromium is located : const browser = await puppeteer.launch({ executablePath: ‘/usr/bin/chromium-browser’ }) Hope this will help … Read more

How to manage log in session through headless chrome?

There is an option to save user data using the userDataDir option when launching puppeteer. This stores the session and other things related to launching chrome. puppeteer.launch({ userDataDir: “./user_data” }); It doesn’t go into great detail but here’s a link to the docs for it: https://pptr.dev/#?product=Puppeteer&version=v1.6.1&show=api-puppeteerlaunchoptions

How to get all console messages with puppeteer? including errors, CSP violations, failed resources, etc

The GitHub issue about capturing console erorrs includes a great comment about listening to console and network events. For example, you can register for console output and network responses and failures like this: page .on(‘console’, message => console.log(`${message.type().substr(0, 3).toUpperCase()} ${message.text()}`)) .on(‘pageerror’, ({ message }) => console.log(message)) .on(‘response’, response => console.log(`${response.status()} ${response.url()}`)) .on(‘requestfailed’, request => console.log(`${request.failure().errorText} … Read more

puppeteer: how to wait until an element is visible?

I think you can use page.waitForSelector(selector[, options]) function for that purpose. const puppeteer = require(‘puppeteer’); puppeteer.launch().then(async browser => { const page = await browser.newPage(); page .waitForSelector(‘#myId’) .then(() => console.log(‘got it’)); browser.close(); }); To check the options avaible, please see the github link.

Puppeteer wait until page is completely loaded

You can use page.waitForNavigation() to wait for the new page to load completely before generating a PDF: await page.goto(fullUrl, { waitUntil: ‘networkidle0’, }); await page.type(‘#username’, ‘scott’); await page.type(‘#password’, ‘tiger’); await page.click(‘#Login_Button’); await page.waitForNavigation({ waitUntil: ‘networkidle0’, }); await page.pdf({ path: outputFileName, displayHeaderFooter: true, headerTemplate: ”, footerTemplate: ”, printBackground: true, format: ‘A4’, }); If there is a … Read more

How to fill an input field using Puppeteer?

Just set value of input like this: await page.$eval(‘#email’, el => el.value=”test@example.com”); Here is an example of using it on Wikipedia: const puppeteer = require(‘puppeteer’); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto(‘https://en.wikipedia.org’, {waitUntil: ‘networkidle2’}); await page.waitForSelector(‘input[name=search]’); // await page.type(‘input[name=search]’, ‘Adenosine triphosphate’); await page.$eval(‘input[name=search]’, el => el.value=”Adenosine … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)