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

How get executed javascript #67

Closed
MHKarami97 opened this issue May 6, 2020 · 3 comments
Closed

How get executed javascript #67

MHKarami97 opened this issue May 6, 2020 · 3 comments
Labels

Comments

@MHKarami97
Copy link

@MHKarami97 MHKarami97 commented May 6, 2020

For example there is some code like this in some website:

<script> var test=12; var test1="num"; var result = test + "/" + test1; </script>

is there a way to get value of result after page loaded completely?
in this code : "12/num"

@FlorianRappl
Copy link
Contributor

@FlorianRappl FlorianRappl commented May 6, 2020

If you have this script as-is on the page then, unfortunately, no.

It's like in a browser - you also cannot get the result of such an evaluation.

@MHKarami97
Copy link
Author

@MHKarami97 MHKarami97 commented May 7, 2020

@FlorianRappl
Thanks, yes it's on page, I get and save it as string, is there way to parse that string as javascript to excute value?

@FlorianRappl
Copy link
Contributor

@FlorianRappl FlorianRappl commented May 7, 2020

From the README:

var numEntries = document.ExecuteScript("document.querySelectorAll('div').length");

Does that help?

Note: The one above only works if you end with an expression, i.e., something that evaluates to a value. If you know already what variable is used, e.g., taking your example above, you could just append result.

Example:

// assumes there is only one script element on the apge
var scriptContent = document.QuerySelector("script").TextContent;
// assumes that the variable we are interested in is called "result"
var result = document.ExecuteScript($"{scriptContent}; result");
@MHKarami97 MHKarami97 closed this May 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.