-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
Can't pass function to evaluationContext (Improvement?) #1474
Comments
@Vandivier i looked into your repository and quickly got lost. Please, feel free to re-file with a repro that would be easier to follow. |
lol. Since when is "I can't understand" a reason to close an issue? Here's the issue in it's simplest form. Consider the following object:
If this object is passed as options to evaluationContext, options.hi exists and options.fpEvaluateInPage does not exist. Or at very least the
|
@Vandivier if I understand correctly, you're passing function from node.js context over to the page context as one of the arguments in the const puppeteer = require('puppeteer');
(async() => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const myObject = {fn: e => 7 + e};
const result = await page.evaluate(myObject => myObject.fn.call(1), myObject);
console.log(result);
await browser.close();
})(); This won't work since const puppeteer = require('puppeteer');
(async() => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const myFunction = e => e + 1;
const result = await page.evaluate(myFunctionText => {
// re-creating function in browser context
const myFunction = new Function(' return (' + myFunctionText + ').apply(null, arguments)');
return myFunction.call(null, 7);
}, myFunction.toString());
console.log(result);
await browser.close();
})(); |
Great! Yes, that is what I was talking about and your solution works. It would be even more convenient, tho, if Puppeteer handled this internally. How do you feel about a PR? |
@Vandivier I'd rather not. We currently rely on a generic notion of Serializable objects, and it's quite easy to predict what will safely cross the boundary and whatnot. Adding a custom codepath for function objects, we'll set a precedent and start an uphill battle with the endless stream of custom serializers/deserializers. We'll never support all the usecases, and it will be hard to predict what's supported. |
Hi is there any way to get progress of a page.evaluate? if I'm doing something like this:
|
anything new on this subject? |
Steps to reproduce
Tell us about your environment:
What steps will reproduce the problem?
Please include code that reproduces the issue.
see https://github.com/Vandivier/data-science-practice/tree/function-to-evaluation-context-repro
clone and execute
npm run-script get-riders
What is the expected result?
Objects will be printed to console which contain the key-value pair 'hi', 'sup', as well as a key 'fpEvaluateInPage' with a function as the value. Additionally, this function should be executed, printing 'hi' to the console on it's own line.
What happens instead?
Objects are printed to console only containing the key-value pair 'hi', 'sup'
The text was updated successfully, but these errors were encountered: