Inject JS in an Angular webpage

Hello everyone,

I got a problem when trying to inject some javascript content in my angular webpage.

This is really weird as it throws an error ‘angular is not defined’ when for example i’m injecting console.log(angular) or just trying to use some angular functions like angular.element .

But when I put it directly in the console, the angular variable is well recognized and it throws no error at all.

Otherwise other basic scripts work well with Ui Path Inject JS like “alert(“something”)”.

What I’m sending in Ui Path :

The error :

Main has thrown an exception

Message: ReferenceError: angular is not defined

Source: Inject js script

Exception Type: ElementOperationException

UiPath.Core.ElementOperationException: ReferenceError: angular is not defined —> System.Runtime.InteropServices.COMException: ReferenceError: angular is not defined
at UiPath.UiNodeClass.InjectAndRunJS(String bstrCode, String bstrInputText)
at UiPath.Core.UiElement.InjectAndRunJS(String code, String input)
— End of inner exception 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)

When I type into the console directly :

Does anybody has an idea oh where it can come from ?

Thanks in advance.

Try something like this in IE (does not work in Chrome).

function AngularinUiPath() {
  var head = document.getElementsByTagName("head")[0];
  var script = document.createElement("script");
  script.src = "//";
  script.onload = function() {
     var scope = angular.element(document.getElementById('GlobalsCtrl')).scope();
1 Like