Solved but unable to mark own answer as solved yet.
We are trying to return the child elements of the 'body' selector in Puppeteer.
The following code works and returns the inner text of the divs:
const page = await browser.newPage();
await page.goto(url);
await page.waitForSelector('body');
const children = await page.$eval('body', el => el.innerText)
console.log(children)
But, when we change the await page.$eval to this, it returns undefined.
const children = await page.$eval('body', el => el.children)
Is there something we are missing?
To add context, our ultimate goal is to use Puppeteer to scrape a React application and render a fiber tree.
Once the tree is built, we are hoping to render it using D3. The goal is for the React application itself to be rendered, then scraped, then have the fiber tree visualized, similar to the Chrome devtools. We took inspiration for using Puppeteer from ReactION. Reinventing the wheel for learning purposes.
The intention with await page.$eval('body', el => el.children)
was to obtain an array of the child elements so we could search for the _reactRootContainer
property.
We are attempting a variation of the below currently but are getting Object reference chain is too long
.
const bodyHandle = await page.$('#root');
const result = await page.evaluateHandle((e) => e.children, bodyHandle);
console.log(result.jsonValue());