question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

page.evalute doesn't seem to work in version 0.13.0

See original GitHub issue

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 0.13.0
  • Platform / OS version: macPS Sierra version 10.12.6

What steps will reproduce the problem?

  await page.goto(`${opts.appUrl}#${opts.localToken}`, {waitUntil: 'networkidle0'});
  
  const header = await page.evaluate(() => {
    const element = document.getElementsByClassName('header');
    console.log(element);
    return element;
  });
  console.log(header)

What is the expected result? I have an almost empty page with a header. If I run the following code the element is logged to the console in the browser in the page.evaluate function. However the next console.log is undefined. I expected it to be the same.

If I run this code in version 0.10.2 it works.

  await page.goto(`${opts.appUrl}#${opts.localToken}`, {waitUntil: 'networkidle'});
  
  const header = await page.evaluate(() => {
    const element = document.getElementsByClassName('header');
    console.log(element);
    return element;
  });
  console.log(header)

The only difference is that networkidle is replaced with networkidle0

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
vsemozhetbytcommented, Dec 13, 2017

There were some changes in result serialization before the 0.13. You can try this:

    const header = JSON.parse(await page.evaluate(() => {
      const element = document.getElementsByClassName('header');
      console.log(element);
      return JSON.stringify(element);
    }));
0reactions
ggorlencommented, Nov 4, 2022

I think document.getElementsByClassName('header'); should be document.getElementsByClassName('header')[0]; or document.querySelector(".header")), else rename const element to const elements. See this SO answer which uses the same code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Puppeteer page.evaluate not working as expected
The code inside page.evaluate is run in the browser context, so the console.log works, but inside the Chrome console and not the Puppeteer ......
Read more >
Puppeteer API v0.13.0 - 作业部落
This method fetches an element with selector , scrolls it into view if needed, and then uses page.mouse to hover over the center...
Read more >
page-evaluate - npm
Monitor web pages for changes. Latest version: 1.1.0, last published: a month ago. Start using page-evaluate in your project by running `npm ...
Read more >
/vendor/puppeteer/docs/api.md | puppeteer_plus@0.12.0 | Deno
When installed, it downloads a version ofChromium, which it then drives using `puppeteer-core`. Being an end-user product, `puppeteer` supports a bunch of ...
Read more >
Changelog — great_expectations documentation
[DOCS] doc-297: update the create Expectations overview page for Data Assistants ... [BUGFIX] fixed a bug where expectation metadata doesn't appear in edit ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found