Different Inject JS behaviour 21.10/22.10 when invoking JS Functions from a web page

With 21.10 we used the Inject JS Activity in a few cases to call JS Functions from a webpage. To do this, we used the pattern suggested here:

this worked reliably. When debugging the same code in Studio 22.10.4 the Inject JS Activity now appears to do nothing (no exception, but also not invoking the desired function).

Trying the pattern suggested here:

also did not yield the desired result. The activity returns a reference error (“func() is not defined”). I did pay attention to the selectors. The surrounding “Attach Browser” Scope targets chrome.exe and for the target of the Inject JS Activity itself, i tried both leaving it empty as well as having it target the html-tag of the website containing the script.

Can JS functions on a website still be invoked in 22.10.x and if yes, how can it be done?

1 Like

Hey @Reich_Tobias

The activity is still supported.

Please show us the js code if possible what are you trying to do ?

Meanwhile I’m checking the JS too.

Thanks
#nK

Can do - but I doubt it provides any benefit beyond what is written in the linked posts.

"function() {window.location.assign(""javascript:DoLogOut()"");}"

this calls a logout function from a webpage. Could be easily replaced with an interface click.

Not so in other cases:
"function() {window.location.assign("""+ in_str_JSFunction +""");}"
where I use it to open sub pages I previously obtained by data table scraping.

The elements marked in yellow call JS Functions which open pages where the robot needs to perform some tasks. Scraping the functions and opening them via the inject gives me a very convenient and reliable way to iterate over the pages. The table otherwise gives me very little options to keep track of where i currently stand, if I had to iterate over the pages with the click-activity (the table might grow, due to new datasets being created while the bot works and the Seq-Numbers start with 1 for each new page, so the number doesn’t help either with identifying what I have already done).

1 Like

Okay thanks for the details. Let me check.

can you try with this?

function(e){....}

Hey @Reich_Tobias

The normal method as usual is working fine. Please post your updates.

Thanks
#nK

Hello @Nithinkrishna
Thanks for trying it out. I suppose the usual method refers to this one?
"function() {window.location.assign(""javascript:myFunc();"");}"

I am not sure what you mean by “please post your updates”. Do you want me to keep you updated on my progress resolving this issue or do you want to know what versions I am running?

In case it’s the latter:
Studio is 22.10.4
Orchestrator Host is 2022.10.2
Edge is 112.0.1722.58 with Extension 22.10.6
Chrome is 112.0.5615.138 with Extension 22.10.6

Dependencies are:
UiPath.System.Activities 22.10.4
UiPath .UiAutomation.Acitivities 22.10.5

Furthermore I tried running the process in question in unattended mode and this appears to work, so that’s a relieve already. It only seems to affect Debugging in Studio.

I’ll try to get a colleague to try to see if this is a “Me-Issue” :slight_smile:

Hello @jack.chan

Thank you for your input. I tried your suggestion. Results in “Reference Error: DoLogOut() is not defined”.
Again: I did pay attention to the selectors. In this case the surrounding Attach Browser targets msedge.exe and the inject js activity targets the top level html element of the page.

1 Like

Hey @Reich_Tobias

Can you please quickly try this & feedback ?

"function() { alert(""test"");}"

I also tried the below working fine,

"function(){ window.location.reload(); }"

Please let me know. If it’s still not working we can see we can connect live.

Thanks
#nK

"function() { alert(""test"");}"

Alert is displayed, but returns:
Inject Js Script: Error HRESULT E_FAIL has been returned from a call to a COM component.

"function(){ window.location.reload(); }"

appears to do nothing.

It seems to depend on the Project (so dependencies or other project specific settings I guess).

"function() {window.location.assign(""javascript:.."");}"
this works if I put this in a new XAML in the (older) Project I succesfully tested unattended earlier (see my post further up).

So its not the Studio Version, Browser, Extension and it’s not different behaviour between debugging/unattended either.

The very same code does not work in a fresh Project. I’ll try to figure out the differences.

Okay @Reich_Tobias I don’t see a problem in the version either.

Please let me know if any further help is needed.