Inject Js Script Error when trying to reach custom objects or functions on a web page with Chrome

Hello all!

First of all I would like to thank you all for this great ocean of information on the forum. It helped a lot and it continues to do so.
This is my first question and believe me I searched my subject :slight_smile: (About 5 hours now)

As the subject explains it clearly, I attach my browser, add “Inject Js Script” activity, and type my function which works perfect on chrome console. (I’m working on PC over a RDP connection)
I got the error: “Inject Js Script: Error HRESULT E_FAIL has been returned from a call to a COM component.”
The longer versions is below:

18.4.0-beta.40+Branch.release/v2018.4.Sha.59fdfa787bdb8f383295f38527b887bf00bf752d

Source: Inject Js Script

Message: Error HRESULT E_FAIL has been returned from a call to a COM component.

Exception Type: UiPath.Core.ElementOperationException

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
UiPath.Core.ElementOperationException: Error HRESULT E_FAIL has been returned from a call to a COM component. ----> System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.
   at UiPath.UiNodeClass.InjectAndRunJS(String bstrCode, String bstrInputText)
   at UiPath.Core.UiElement.InjectAndRunJS(String code, String input)
   --- End of inner ExceptionDetail stack trace ---
   at UiPath.Core.Activities.ScopeActivity.OnFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
   at System.Activities.Runtime.FaultCallbackWrapper.Invoke(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
   at System.Activities.Runtime.FaultCallbackWrapper.FaultWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

But when I try to run something like “alert(‘my test’)” it works.

I have some ideas about the problem but I’m not sure. Maybe UiPath chrome extensions attaches itself to the top layer and can not call its properties? I’m really guessing here.
By the way, I did everything on Chrome Extension Troubleshoot page.
Also reinstalled UiPath, restarted the machine.

I really appriciate if you have any idea about this problem.

Thank you!

I met the similar error…

18.4.4+Branch.support/v2018.4.Sha.f763d4ae80fa90017d15cf7fd8625d0b338b8116

Source: Inject js script

Message: Exception from HRESULT: 0x80020101

Exception Type: UiPath.Core.ElementOperationException

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
UiPath.Core.ElementOperationException: Exception from HRESULT: 0x80020101 ----> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x80020101
at UiPath.UiNodeClass.InjectAndRunJS(String bstrCode, String bstrInputText)
at UiPath.Core.UiElement.InjectAndRunJS(String code, String input)
— End of inner ExceptionDetail stack trace —
at UiPath.Core.Activities.ScopeActivity.OnFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
at System.Activities.Runtime.FaultCallbackWrapper.Invoke(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
at System.Activities.Runtime.FaultCallbackWrapper.FaultWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

Hi @Kimmer_Wang

Please see here, it seems to be an error with your script:

Hi, thanks for your help!
My JS script plays well with IE. But problem with UiPath…Below is my JS script:

function getTable(){
    var arr = 'table*class*table'.split('*');
    var tag = arr[0];
    var attr = arr[1];
    var value = arr[2];
    var aElements=document.getElementsByTagName(tag);
    var aEle;
    for(var i=0;i<aElements.length;i++){
	if(aElements[i].getAttribute(attr)==value){
	aEle = aElements[i];
	}
    }
    var mytable = aEle;
    var data = [];

    for(var i=0,r=mytable.rows.length; i<r; i++){

        for(var j=0,cells=mytable.rows[i].cells.length; j<cells; j++){

            if(!data[i]){

                data[i] = new Array();

            }

            data[i][j] = mytable.rows[i].cells[j].innerHTML;

        }

    }

    alert (data.length);
    return data;

}

UiPath Error: ** Maybe UiPath does not support ‘split’ ??? **

18.4.4+Branch.support/v2018.4.Sha.f763d4ae80fa90017d15cf7fd8625d0b338b8116

Source: Inject Js Script

Message: ArrayConverter cannot convert from System.String.

Exception Type: System.NotSupportedException

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.NotSupportedException: ArrayConverter cannot convert from System.String.
at UiPath.Core.Activities.ScopeActivity.OnFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
at System.Activities.Runtime.FaultCallbackWrapper.Invoke(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
at System.Activities.Runtime.FaultCallbackWrapper.FaultWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

I would suggest minimizing the script to the point it works and going from there. It is hard to judge exactly what is the cause.

I’ve found this problem today and would like to share my solution. Seems that extensions (like UiPath’s extension) in Chrome have a limited view of the window object, or at least, seems to execute on a different context where no custom properties or objects defined by the page are reachable. More info here: https://stackoverflow.com/questions/12395722/can-the-window-object-be-modified-from-a-chrome-extension

As a workaround, you can use any of the methods described in the StackOverflow article. In may case, both setting window.location with javascript protocol or injecting a new tag worked nicely.

Hi @jblancor, What if I want to invoke the global functions of a web page, I tried it but it is giving me error.