Skip to content

Conversation

@aslushnikov
Copy link
Contributor

Fixes #2021.

a.b = b;
return a;
});
expect(result).toBe(undefined);
Copy link
Contributor

@Janpot Janpot Feb 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aslushnikov Is there any reason on why this should return undefined? I think throwing an error would be more appropriate. Think of the consumer of this API. They will not realise their result is circular, or it might happen only in some occasions. Or maybe sometimes undefined is a legit output of their function. How will they be able to distinguish these cases from a bug? How will they be notified of bugs in their code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Janpot the motivation behind this was to let people use page.evaluate safely without caring on the return value. Consider the following simple script:

await page.evaluate(() => window.foo = window);

Technically, the page.evaluate should throw since the expression returns non-serializable value,
but most of the time its unintentional.

How will they be able to distinguish these cases from a bug? How will they be notified of bugs in their code?

I filed #2079 with a solution that will hopefully address your concerns and satisfy our usecase.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aslushnikov How did you arrive at this conclusion: but most of the time its unintentional.?
In my experience it's exactly the opposite, I've never had to evaluate and not care about the result.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you arrive at this conclusion: but most of the time its unintentional.?

@Janpot once we started throwing errors, we instantly had a bunch of feedback on both bugtracker and internally about the unwanted errors caused by one-liners in page.evaluate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I don't really agree with API design like this but I see you want to be sort of pragmatic, and I don't have arguments against that that would actually change your mind 🙂. I'll settle for

async function evaluate (page, ...args) {
  const result = await page.evaluate(...args);
  if (result === puppeteer.UNSERIALIZABLE_VALUE) {
    throw new Error('Unserializable value');
  }
  retun result;
}

then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants