0

I can get access to the entire HTML for any URL by opening dev-tools and typing:

document.documentElement

I am trying to replicate the same behavior using puppeteer, however, the snippet below returns {}

const puppeteer = require('puppeteer'); // v 1.1.0
const iPhone = puppeteer.devices['Pixel 2 XL'];

async function start(canonical_url) {
  const browserURL = 'http://127.0.0.1:9222';
  const browser = await puppeteer.connect({browserURL});

  const page = await browser.newPage();
  await page.emulate(iPhone);
  await page.goto(canonical_url, {
    waitUntil: 'networkidle2',
  });

  const data = await page.evaluate(() => document.documentElement);
  console.log(data);
}

returns:

{}

Any idea on what I could be doing wrong here?

anurag
  • 560
  • 6
  • 13
  • 1
    As the documentation says, only serializable values can be returned e.g. document.documentElement.innerHTML. – wOxxOm Aug 28 '20 at 04:53
  • Does this answer your question? [Get elements from page.evaluate in Puppeteer?](https://stackoverflow.com/questions/53032903/get-elements-from-page-evaluate-in-puppeteer) – wOxxOm Aug 28 '20 at 04:55
  • @wOxxOm: thx for the suggestion, the link you sent partially answers the question. I also opened a bug with puppeteer and detailed info is at https://github.com/puppeteer/puppeteer/issues/6370 – anurag Aug 30 '20 at 03:08

0 Answers0