Error: Evaluation failed: ReferenceError in waitForFunction
See original GitHub issueWhen calling the following code:
[...]
const options = {
page: await browser.newPage()
};
await utils.fetchPage("someurl", ".some-selector", options);
with the following fetchPage implementation:
async function fetchPage(p_url, p_waitForSelectors, p_options) {
assert(p_options.hasOwnProperty('page'));
await p_options.page.goto(p_url, {waitUntil: 'networkidle2'});
if (p_waitForSelectors) {
await p_options.page.waitForFunction(() =>
document.querySelectorAll(p_waitForSelectors).length
);
}
const html = await p_options.page.content();
assert(html);
return html;
}
I get the error:
[17:39:49] [ERROR] Error: Evaluation failed: ReferenceError: p_waitForSelectors is not defined
at eval (eval at waitForPredicatePageFunction (:2:23), <anonymous>:4:30)
at eval (eval at waitForPredicatePageFunction (:2:23), <anonymous>:4:57)
at onRaf (<anonymous>:49:35)
at pollRaf (<anonymous>:42:15)
at waitForPredicatePageFunction (<anonymous>:7:22)
at ExecutionContext._evaluateInternal (\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:217:19)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async WaitTask.rerun \node_modules\puppeteer\lib\cjs\puppeteer\common\DOMWorld.js:528:23)
When replacing p_waitForSelectors with the explicit string literal ".some-selector" all works fine:
[...]
await p_options.page.waitForFunction(() =>
document.querySelectorAll(".some-selector").length
);
[...]
Is this some weird JavaScript quirk that I somehow misunderstand? Or is this a genuine bug?
I’m using Puppeteer 5.5.0.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Error: Evaluation failed: ReferenceError: res is not defined
Official document - The method returns a Promise which resolves to the return value of pageFunction. This mean you can get back a...
Read more >Evaluation failed: ReferenceError: req is not defined". Im using ...
I get the error "Error: Evaluation failed: ReferenceError: req is not defined". Im using puppeteer and im trying to get the clients input...
Read more >Puppeteer Evaluation failed: ReferenceError: __awaiter is ...
I am using Puppeteer with TypeScript and when I try to evaluate an async function on a page: await page.evaluate(async function() { //...
Read more >Page.evaluate() method - Puppeteer
Evaluates a function in the page's context and returns the result. If the function passed to page.evaluateHandle returns a Promise, the function will...
Read more >Waiting for text to display on a page with Puppeteer
Here is a (pseudo-code) solution to this problem: ... The core of this solution leverages Puppeteer's waitForFunction in conjunction with a ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

That fixed it! @vsemozhetbyt thanks so much for the help!
It finally works by adding:
Now I’m working on how to get the result of
fn