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

Investigate: passing a str to evaluate that should return an obj, returns nothing #81

Closed
1 task
ebebbington opened this issue Aug 11, 2021 · 1 comment
Closed
1 task
Labels
Type: Chore Merging this pull request results in a patch version increment

Comments

@ebebbington
Copy link
Member

Summary

What:

As it stands, you can pass a command as a string to evaluatePage where that command returns an object, eg:

await sinco.evaluatePage(`document.querySelector('a').getBoundingClientRect()`) // the command in the dom returns an obj

But the value property doesnt exist on the response. I think i've seen this before, if a command that returns an object is passed to Runtime.evaluate wont return anything

What I propose is we investigate using Runtime.callFunctionOn for both strings AND functions, but this needs ot be tested to see if we cna do that. For example im thinking:

evaluate(command: str | Function) {
  // Logic for handling if a string will be removed

  if (command is a string) command = () => command
  // Then existing logic
  const { executionContextId } = await this.sendWebSocketMessage(
        "Page.createIsolatedWorld",
        {
          frameId: this.frame_id,
        },
      );

      const { result } = await this.sendWebSocketMessage(
        "Runtime.callFunctionOn",
        {
          functionDeclaration: pageCommand.toString(),
          executionContextId: executionContextId,
          returnByValue: true,
          awaitPromise: true,
          userGesture: true,
        },
      );
      return result.value;
}
evaluate(doc.querySelector(selector))

Why:

I think it's just a limitation of that runtime method

Acceptance Criteria

Below is a list of tasks that must be completed before this issue can be closed.

  • Write tests for ensuring we can return an object from the evaluatePage method
@ebebbington ebebbington added Type: Chore Merging this pull request results in a patch version increment Priority: Low labels Aug 11, 2021
@ebebbington
Copy link
Member Author

I've investigated, and found that there isn't anything we can do. Thats just the nature of the API, it won't return class based objects, BUT it would return a pure object, eg something.toJson() or { name: 2 }.

Tested with puppeteer, and i experienced the same thing

Closing because there's nothing that we can do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Chore Merging this pull request results in a patch version increment
Development

No branches or pull requests

1 participant