0

I'm following this tutorial in order to get the Console Tool out of the Terminal via puppeteer Access browser console from a terminal?

But it looks like all I get is a JSON output without the console information I am in need of.

{
    "origin": "http://localhost:81",
    "pathname": "/messing7-js-playground/jsdom.html"
}

I have modified the script of the tutorial to make it workable for my system, so this is what I am executing

const puppeteer = require('puppeteer')

;(async () => {
¦•const browser = await puppeteer.launch({
¦•••|headless: true,
¦•••|args: [
¦•••|•••¦'--no-sandbox',
¦•••|•••¦'--disable-setuid-sandbox',
¦•••|]
})
¦•const page = await browser.newPage()

await page.goto('http://localhost:81/messing7-js-playground/jsdom.html')

¦•const retrievedData = await page.evaluate(() => {

¦•••const { origin, pathname } = window.location;

¦•••return {
¦•••|•origin,
¦•••|•pathname,
¦•••}
¦•})

¦•const retrievedJSON = JSON.stringify(retrievedData, null, 4)

¦•console.log(retrievedJSON)

¦•await browser.close()
})()

I would appreciate you guiding me into the right direction.

  • The linked thread appears to describe creating a repl for inputting into the terminal. If you're just trying to capture console output, is [How do print the console output of the page in puppeter as it would appear in the browser?](https://stackoverflow.com/questions/58089425/how-do-print-the-console-output-of-the-page-in-puppeter-as-it-would-appear-in-th) what you want? What console information are you in need of, specifically? The code you've shown appears working -- you returned and logged precisely `origin, pathname` as the evaluate call says. – ggorlen Sep 26 '21 at 13:29

0 Answers0