Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

349
Views
Passing arguments to page.evaluate (puppeteer) when used with pkg builds

I am using puppeteer and the script works fine when executing directly with node.

However, as soon as I build the source with pkg - page.evaluate and page.waitForFunction functions start failing with the error SyntaxError: Unexpected identifier.

The code in question is

await page.evaluate((el) => {return el.value}, element)

The reason it does not work is because pkg compiles scripts using v8::ScriptCompiler the sources are not kept. So basically (el) => {return el.value} is changed to native code. More details here.

So the solution is to pass a string to page.evaluate instead of a function.

I have been able to achieve this with a not-so-nice looking quirky hack.

page.evaluate(
    `(() => {
        let els=document.querySelectorAll("${selector}");
        let el = els[0];
        return el.value;
    })();`
);

But this gets quite messy, since I am using xpath selectors as well as css.

What I want to do is something like this

page.evaluate(
    `((el) => {
        return el.value;
    })();`, element
);

But el is undefined here (in browser context). I have been trying to make this work for many hours now. Any help will be greatly appreciated.

Other references

pkg

Cannot pkg puppeteer app due to ExecutionContext.js - SyntaxError: Unexpected identifier

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!