Jump to content
UBot Underground

[Solved] JavaScript calls and returns


Recommended Posts

I am trying to get a bot to run a JavaScript that contains some statements and calls to other JS functions. After that it should return a variable that will be used by Ubot.

 

However, I seem to be completely out in the blue on this one (too :) ).

 

Does anyone have any experiences with this? Is it possible to return values with the "run javascript" command? Do the values that are set during Run JavaScript, "die" after the execution has finished and the command node is exited, so that they can't be accessed later on in the bot?

 

 

I am grateful for any input, I am stuck right now. Just thinking in other ways might even get me on track again.

 

 

By the way, this is the code:

 



var client = new XMLHttpRequest();
client.open("GET", "{#urlToCheck}", true);
client.send();
client.onreadystatechange = function() {
 if(this.readyState == 2) {
   print(this.getAllResponseHeaders());
 }
}

var test = this.getAllResponseHeaders()

 

 

This code snippet should get the header of the response object. It is supposed to be supported by Chromium which I believe is what UB4 uses.

No matter the script, my question is more on a general level of JavaScript & UB4.

Link to post
Share on other sites
I am trying to get a bot to run a JavaScript that contains some statements and calls to other JS functions. After that it should return a variable that will be used by Ubot.

 

However, I seem to be completely out in the blue on this one (too ).

 

Does anyone have any experiences with this? Is it possible to return values with the "run javascript" command? Do the values that are set during Run JavaScript, "die" after the execution has finished and the command node is exited, so that they can't be accessed later on in the bot?

 

 

I am grateful for any input, I am stuck right now. Just thinking in other ways might even get me on track again.

 

 

By the way, this is the code:

 



var client = new XMLHttpRequest();
client.open("GET", "{#urlToCheck}", true);
client.send();
client.onreadystatechange = function() {
 if(this.readyState == 2) {
   print(this.getAllResponseHeaders());
 }
}

var test = this.getAllResponseHeaders()

 

 

This code snippet should get the header of the response object. It is supposed to be supported by Chromium which I believe is what UB4 uses.

No matter the script, my question is more on a general level of javaScript.

 

I think they die and the only way to return is using $eval but not 100% sure. Be interested in hearing Eddies take.

Link to post
Share on other sites

It looks like you might be overcomplicating what you want to do.

 

There's no reason to run the request asynchronously when you just want to wait for the result. If you run it asynchronously, it is going to send the request and try to return the result before the request is finished.

 

Here's the code view of how you could get the headers of a request.

 

ui text box("website", #website)

set(#headers, $eval("var client = new XMLHttpRequest();
client.open(\"HEAD\", \"{#website}\", false);
client.send();
client.getAllResponseHeaders();"), "Global")

 

A few things to note.

 

We set the last parameter of open to false, which means it will wait for the request to finish before continuing.

 

We set the request type to HEAD, which means it will only request the headers from the server, instead of the entire document, which will make it a little faster.

 

Hope that helps :)

  • Like 1
Link to post
Share on other sites

You truly ROCK, Eddie!

 

...but I don't seem to get GET to work, I actually do need both the page AND the header, but I guess I will find out how.

 

(and yes, you are absolutely right, no need to overcomplicate things)

 

 

 

Thanks!

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...