Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling evaluate function on Puppeteer from results in a ReferenceError #3108

Closed
josdirksen opened this issue Aug 23, 2017 · 2 comments
Closed
Labels
wontfix We decided not to fix this issue/not implement that feature request.

Comments

@josdirksen
Copy link

I've been playing and experimenting with Scala.js and wanted to check out the new Puppeteer API from the chrome guys to automate Chromium. Most of it works as expected, but when I try and call the evaluate function (https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pageevaluatepagefunction-args). I've tried different approaches of providing the js.Function, but all result in the same error.

ReferenceError: $this$5 is not defined

The code for this example can be found in: https://github.com/josdirksen/scalajs-puppeteer

@sjrd already mentioned in gitter that it is probably because of some serialization magic in puppeteer.

@josdirksen So ... from https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#
pageevaluatepagefunction-args it seems that it indeed does some serialization magic. I'm afraid 
that won't be supported by Scala.js as such, because it means puppeteer peeks into the 
compiler's internal encoding, which a reasonable library should never do.

If this is really something out of the scope of scala.js feel free to immediately close this :)

@sjrd
Copy link
Member

sjrd commented Aug 23, 2017

I did some digging, and it is indeed what I was afraid of. After some indirections, evaluate ends up calling evaluationString(fun, ...). That function basically calls fun.toString(), which for a function returns the raw JS source code of the function. It then, I guess, sends that string over the wire and tries to execute it in a completely different environment, where it has lost its lexical scope.

I'm afraid puppeteer is doing something evil here, that cannot be supported by Scala.js. So I'll close this as a won't fix.

@sjrd sjrd closed this as completed Aug 23, 2017
@sjrd sjrd added the wontfix We decided not to fix this issue/not implement that feature request. label Aug 23, 2017
@josdirksen
Copy link
Author

Completely agree. Will work around this, and pass in Strings instead of functions. Thanks for the quick reply and explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix We decided not to fix this issue/not implement that feature request.
Projects
None yet
Development

No branches or pull requests

2 participants