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

encountered an undefined value #526

Closed
zdwork opened this issue Nov 27, 2019 · 9 comments
Closed

encountered an undefined value #526

zdwork opened this issue Nov 27, 2019 · 9 comments
Labels

Comments

@zdwork
Copy link

zdwork commented Nov 27, 2019

var res string
chromedp.EvaluateAsDevTools("window.scrollTo(0,document.body.scrollHeight);",&res),

Hello, this printing error
2019/11/27 18:06:54 encountered an undefined value

@mvdan
Copy link
Contributor

mvdan commented Nov 27, 2019

If you run that in your browser console, it does return undefined. Why are you trying to obtain the result as a string?

Please think about these issues before filing new issues. I do not offer free support for questions that can be solved with a bit of thinking and googling.

@mvdan mvdan added the question label Nov 27, 2019
@zdwork
Copy link
Author

zdwork commented Nov 27, 2019

res runtime.RemoteObject

You can't do this only once

@mvdan
Copy link
Contributor

mvdan commented Nov 29, 2019

Sorry, but I don't understand.

@mvdan
Copy link
Contributor

mvdan commented Jan 12, 2020

Closing because I still don't know what this is about.

@mvdan mvdan closed this as completed Jan 12, 2020
@zhangguanzhang
Copy link

chromedp.EvaluateAsDevTools("window.scrollTo(0,document.body.scrollHeight);a="1",&res),

@welldonexing
Copy link

what the hell is chromedp.Evaluate function juse a undefined result ,why to case panic in go , that is holy shit code

@ahmetb
Copy link

ahmetb commented Nov 25, 2020

@mvdan I think I understand what they are saying.

If chromedp.Evaluate action returns an undefined value, it currently results in this mentioned error. They are trying to figure out a way to ignore that. I think the easy way is to add || true to the command they're running.

Perhaps the way to solve this in the library could be to relax the requirement on the res parameter and require it only if there's a return value (that is, not "undefined"). This way, if the Evaluate returns "undefinded, and res==nil,

@ZekeLu
Copy link
Member

ZekeLu commented Apr 1, 2021

A note for whom encounters the same issue and gets here: besides constructing the javascript to make sure it returns a value other than undefined (as suggested by @ahmetb), we can use runtime.RemoteObject to capture the undefined value:

Please note that res should be of type *runtime.RemoteObject instead of runtime.RemoteObject.

var res *runtime.RemoteObject
chromedp.EvaluateAsDevTools("window.scrollTo(0,document.body.scrollHeight);",&res),

@ZekeLu
Copy link
Member

ZekeLu commented May 8, 2021

After #816 is merged, you can simply write:

EvaluateAsDevTools("window.scrollTo(0,document.body.scrollHeight);", nil),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants