Inject JS activity with async function

Hello there!

I am trying to use inject js activity but code inside is async function, and, as known async function returns as a promise, but i want to return resolved value, which in my case is string. Can someone suggest how to do it?

Thank you in advance!

Hi @ustuyanovmaksim,

To get the resolved value of a promise returned by an async function in UiPath, you can use the “Await” activity in combination with the “Invoke Code” activity.

Here is an example code snippet that you can use to execute your async JavaScript function and get the resolved value as a string:

scssCopy code

// define your async function as a string
string jsFunction = @"
async function getAsyncString() {
  // your async code here
  return 'resolved value';

// create a new instance of the Chrome browser
var chrome = new ChromeBrowser();

// execute the async function using the "Inject Js Script" activity
var task = chrome.InjectJsScript(jsFunction);

// wait for the task to complete and get the resolved value as a string
var result = Await(task).ToString();

In the above code, replace the getAsyncString() function with your own async JavaScript function that returns a promise. The result variable will contain the resolved value of the promise as a string.

i would really appreciate having it as an xml emaple, because i didnt really get how to do it (i am newbie). So if you can, please can i ask you to make some example as a workflow?