Puppeteer unable to run on Heroku

Here is what worked for me. First, I clear all my buildpacks and then I added the puppeteer-heroku-buildpack and the heroku/nodejs one: $ heroku buildpacks:clear $ heroku buildpacks:add –index 1 https://github.com/jontewks/puppeteer-heroku-buildpack $ heroku buildpacks:add –index 1 heroku/nodejs Then, add the following args to the puppeteer launch function: const browser = await puppeteer.launch({ ‘args’ : [ … Read more

Headless browser detection

There is a headless browser detection test which tests for the following: Does the User-Agent contain the string “HeadlessChrome”? Is navigator.webdriver set? Is window.chrome unset? Does the browser skip asking for permissions (like notifications)? Are browser plugins unavailable? Is navigator.languages unset? If your browser answers any of these questions with yes, then you fail the … Read more

Puppeteer in NodeJS reports ‘Error: Node is either not visible or not an HTMLElement’

If your code looks like this const button = await page.$(selector); await button.click(); Try changing await button.click(); to await button.evaluate(b => b.click()); The difference is that button.click() clicks using Puppeteer’s ElementHandle.click() which scrolls the page until the element is in view gets the bounding box of the element (this step is where the error happens) … Read more

How to pass a function in Puppeteers .evaluate() method?

You cannot pass a function directly into page.evaluate(), but you can call another special method (page.exposeFunction), which expose your function as a global function (also available in as an attribute of your page window object), so you can call it when you are inside page.evaluate(): var myFunc = function() { console.log(“lol”); }; await page.exposeFunction(“myFunc”, myFunc); … 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 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