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 evaluate is throwing syntax error if I bundle the script with pkg

See original GitHub issue

When I use page.evaluate (puppeteer 1.12.0, chrome 65 installed in program files directory windows 7) in script, I was able to run it when I invoke script using node src/app.js.
But, When I package the script into an executable using pkg (https://github.com/zeit/pkg/), page.evaluate is throwing an error saying syntax error in evaluatehandle line 79. I had to build with pkg because my production environment doen’t have node.js

Please help me with this.

Environment: Node: 9.3 OS: windows 7 pkg: 4.3.1 Executable Target: node9-win (pkg would built an exe for node9 & windows) Chrome: 65 (installed on my pc; not from local chromium)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
aslushnikovcommented, Jun 6, 2019

Thank you for your reply. What about if I need to pass arguments. For example, suppose I need to pass an object as argument

@neuhausi you can inline it as a part of the function call:

const puppeteer = require('puppeteer');

const obj = {
  "foo" : true,
  "bar": false
}

function myFunction(obj){
  return obj.foo;
}

(async function main() {
  const browser = await puppeteer.launch();
  const [page] = await browser.pages();
  await page.goto('https://aslushnikov.com');
  console.log(await page.evaluate(`(${myFunction.toString()})(${JSON.stringify(obj)})`));
  await browser.close();
})();
1reaction
neuhausicommented, Jun 5, 2019

Thank you for your reply. What about if I need to pass arguments. For example, suppose I need to pass an object as argument

const puppeteer = require('puppeteer');

const obj = {
  "foo" : true,
  "bar": false
}

function myFunction(obj){
  return obj.foo;
}

(async function main() {
  const browser = await puppeteer.launch();
  const [page] = await browser.pages();
  await page.goto('https://aslushnikov.com');
  console.log(await page.evaluate(`(${myFunction.toString()})()`));
  await browser.close();
})();
Read more comments on GitHub >

github_iconTop Results From Across the Web

Page evaluate is throwing syntax error if I bundle the script ...
I was able to guess the reason. The issue is with pkg . While building the exe , it is compiling/transpiling code. This...
Read more >
Passing arguments to page.evaluate (puppeteer) when used ...
I am using puppeteer and the script works fine when executing directly with node. However, as soon as I build the source with...
Read more >
Script syntax error checking
All script fields provide controls for checking the syntax for errors and for locating the error easily when one occurs.
Read more >
When Things Go Wrong — PyArmor 7.6.0 documentation
Just think it as a common python script, check whether the module, package or extension file locates in the right place according to...
Read more >
API - ESBuild
esbuild app.js --bundle --alias:oldpkg=newpkg require('esbuild'). ... There you can use regular JavaScript syntax to eliminate cross-platform differences.
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