Puppeteer log inside page.evaluate

后端 未结 10 1006
野的像风
野的像风 2020-12-01 04:34

How can I console.log something inside the page.evaluate, passing it to node and using it during the evaluation of the page?

I actually want to log

10条回答
  •  独厮守ぢ
    2020-12-01 05:07

    **Updated to work with puppeteer v1.4.x

    If all you want is to "log the progress of the page.evaluate to the console", then just

    const page = await browser.newPage();
    
    page.on('console', consoleObj => console.log(consoleObj.text()));
    

    And use console.log in page.evaluate as usual, no more dependencies are required.

    Also see this nice tweak to remove multiple annoying warnings from log.

提交回复
热议问题