Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puppeteer page.evaluate not working as expected

Tags:

puppeteer

Can someone explain why this code isn't working. I have a console log before I run page.evaluate() which logs what I expect, but the console log inside page.evaluate never runs.

const puppeteer = require('puppeteer');

(async () => {
  try {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto('https://www.example.com');
    page.on('response', async response => {
      const url = response.url();
      if (url.includes('something')) {
        console.log('this code runs');
        await page.evaluate(() => {
          console.log("this code doesn't run");
        });
      }
    });    
  } catch (err) {
    console.log(err);
  }
})();

like image 566
Nic Stelter Avatar asked Sep 22 '19 02:09

Nic Stelter


1 Answers

Console log doesn't work in page.evaluate()

https://github.com/GoogleChrome/puppeteer/issues/1944

like image 116
Nic Stelter Avatar answered Sep 17 '22 16:09

Nic Stelter