Is it possible to get Chrome API responses without looking at the console using Inject Js Script activity?

I am clicking a button on a web page that calls an API and generated the response below. Is there a way to get the response value programmatically without having UiPath open the console?

I know there is a way to call the API, but the website is not mine, so I am unsure what variables to pass.

Since the API response is visible in the browser, it means the browser already has the JSON in memory.

You can use Java script to extract it, use the script in UiPath using inject JS acrivity

Thanks for the reply.

Any pointers on where to begin with this script? I am not too familiar with JavaScript. Is there a specific function you are referring to?

Are you using any specific url and also which browser you are using this?
Give me basic details, ill test for function

1 Like

An example link is Steffes Group | Richard Schlichtmann Estate Farm Auction Lot Listings

I’m clicking the number of bids in the item listing to call the API and generate the JSON response.

Use this in JS activirty.

"(function() {
var open = XMLHttpRequest.prototype.open;
var send = XMLHttpRequest.prototype.send;

XMLHttpRequest.prototype.open = function(method, url) {
    this._url = url;
    open.apply(this, arguments);
};

XMLHttpRequest.prototype.send = function(body) {
    this.addEventListener('load', function() {
        if (this._url.includes('track')) {
            window.lastApiResponse = this.responseText;
        }
    });
    send.apply(this, arguments);
};

})();"

1 Like

I’ll give that code a try if I have time today. Thanks a bunch!

I created a sample local HTML file (LocalHTMLPage.html) that performs a RestAPI call in the backend when you press the Search Users button.

It uses two Inject Js Script activities:

Inject Js Script - Verify if you can detect ANY network activity

Inject Js Script - Get the API data

Before the Inject Js Script - Get the API data perform the UI element action that will trigger the Rest API call. Use delays between actions so it will get a successful loaded Rest API call with results.

Use the attached Studio 2025.10.1 project as reference.
InterceptRestAPIWithInjectJsScriptActivity.zip (1.8 MB)

Created and tested under Studio 2025.10.1

Windows project compatibility with VB.Net language

This UiPath Studio project is an API monitoring and data extraction automation that performs the following tasks:

:bullseye: Main Purpose

The project monitors and captures REST API calls made by a web application, then extracts and logs the API response data for analysis.

:wrench: Workflow Breakdown

1. Application Setup

  • Opens a local HTML file (LocalHTMLPage.html) containing a “User Management System”

  • Uses Microsoft Edge browser

  • Maximizes the browser window

2. JavaScript Injection for API Monitoring

Injects a script that intercepts all network requests:

  • Monitors XMLHttpRequest (traditional AJAX calls)

  • Monitors Fetch API (modern JavaScript requests)

  • Captures detailed information for each API call:

  • Request type (XHR/Fetch)

  • URL

  • HTTP method

  • Status code

  • Response headers

  • Response body

  • Timestamp

3. User Interaction

  • Clicks the “Search Users” button on the web page

  • This triggers the actual REST API calls that will be intercepted

4. Data Extraction & Processing

  • Retrieves captured API data using another JavaScript injection

  • Parses JSON responses using Newtonsoft.Json

  • Extracts specific API details:

  • type (request type)

  • url (API endpoint)

  • method (HTTP method)

  • status (HTTP status code)

  • responseBody (actual API response data)

  • timestamp (when the call was made)

5. Logging & Output

  • Logs all extracted API information to the UiPath output panel

  • Provides detailed trace of the API monitoring results

:hammer_and_wrench: Technical Components

Variables Used:

  • out_GetAPIData_JSON - Raw JSON array from JavaScript

  • jArray, firstItem - For JSON parsing

  • out_type, out_url, out_method, etc. - Extracted API properties

Key Activities:

  • NInjectJsScript - JavaScript injection for monitoring

  • NClick - UI interaction

  • DeserializeJson - JSON parsing

  • MultipleAssign - Extracting multiple properties

  • LogMessage - Output results

:bar_chart: What It Achieves

  1. Real-time API Monitoring: Captures all REST API calls made by the web application

  2. Data Extraction: Pulls out specific API details (URLs, methods, responses)

  3. Structured Output: Formats the data for easy analysis

  4. Testing Tool: Useful for QA testing, API debugging, and monitoring web application behavior

:bullseye: Use Cases

  • API Testing: Verify that web applications make correct API calls

  • Performance Monitoring: Track API response times and success rates

  • Debugging: Identify issues with API endpoints or data formats

  • Data Extraction: Capture API responses for further processing

  • Security Testing: Monitor what data is being sent/received

:magnifying_glass_tilted_left: Expected Output

When you run this automation, you’ll see logs showing:

  • The API endpoints called (like https://jsonplaceholder.typicode.com/users)

  • HTTP methods used (GET, POST, etc.)

  • Status codes (200, 404, etc.)

  • The actual JSON response data from the APIs

  • Timestamps of when calls were made

This is essentially a web API monitoring robot that helps you understand and analyze the backend communication of web applications!

Have you tried Application Event Trigger? With a <html /> selector, you can monitor web requests Activities - Application Event Trigger

I likely have something wrong, but I am getting an error when running this activity - Inject Js Script: TypeError: n is not a function

I don’t see anything wrong with your code, so I assume it is something I’ve done incorrectly.

Set input parameter to New List(Of Object).

I set Input parameter to New List(Of Object) and it says it cannot be converted to String.

Got it since our script does not require any input, so let’s set: Input Parameter = “”

I changed input parameter to “”. Same error has before - n is not a function.

When you writing script , don’t enclose in “”. Give only code.

Many errors when not enclosing my script in quotes.

Try the steps exactly as follows: Use an empty string "" as the Input parameter, and set Execution World = Page so the script runs in the actual page context. Then inject the following JS without quotes to intercept the API call:

(function () {
    const open = XMLHttpRequest.prototype.open;
    const send = XMLHttpRequest.prototype.send;

    XMLHttpRequest.prototype.open = function (method, url) {
        this._url = url;
        open.apply(this, arguments);
    };

    XMLHttpRequest.prototype.send = function (body) {
        this.addEventListener('load', function () {
            if (this._url.includes('YOUR_API_KEYWORD')) {
                window.lastApiResponse = this.responseText;
            }
        });
        send.apply(this, arguments);
    };
})();

After triggering the action that makes the API call, run a second Inject JS Script (again with Input = "") containing:

return window.lastApiResponse;

This returns the captured API response to UiPath.

@jholliday

the same data might be coming on ui as well right..any specific reason why you want to extract from console only?

cheers

@Dan_Munteanu
From my tries, the Application Event Trigger for click doesn’t work for default selector and UI default framework, as it expects an app selector from Active Accessibility.

Invalid Trigger. Only 'app' attribute is allowed for 'html' selector. Exception Type: UiPath.UIAutomationNext.Exceptions.UiAutomationException in .local\generated\Triggers.Generated.xaml at NNativeEventTrigger`1 "Application Event Trigger 'Search Users'" at TriggerScope "TriggerScope" at Sequence "Sequence" at Sequence "Sequence" at Triggers_Generated "Triggers.Generated" UiPath.UIAutomationNext.Exceptions.UiAutomationException: Invalid Trigger. Only 'app' attribute is allowed for 'html' selector. ---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x80040329 at UiPath.UiNodeMonitorClass.MonitorNativeEvent(String bstrSelector, String nativeEvent, Boolean isCollapsable, Boolean matchSync, Boolean matchChildren, Boolean searchInvisibleChildren, String bstrServerUrlForBrowserEvents) at UiPath.UIAutomationNext.Triggers.EventMonitor.<>c__DisplayClass23_0.<RegisterNativeEventInternal>b__0() at UiPath.UIAutomationNext.Services.DriverServiceCore.WrapCom[T](Func`1 toExecute) --- End of inner exception stack trace --- at UiPath.UIAutomationNext.Extensions.ExceptionExtensions.GetFriendly(COMException comException) at UiPath.UIAutomationNext.Extensions.ExceptionExtensions.ThrowFriendly(COMException comException) at UiPath.UIAutomationNext.Services.DriverServiceCore.WrapCom[T](Func`1 toExecute) at UiPath.UIAutomationNext.Triggers.EventMonitor.RegisterNativeEventInternal(SelectorTriggerNativeEventData triggerData, Boolean saveMonitorId) at UiPath.UIAutomationNext.Triggers.EventMonitor.<RegisterNativeEvent>b__19_0(SelectorTriggerNativeEventData t) at System.Linq.Utilities.<>c__DisplayClass2_0`3.<CombineSelectors>b__0(TSource x) at System.Linq.Enumerable.SelectEnumerableIterator`2.ToList() at UiPath.UIAutomationNext.Triggers.EventMonitor.RegisterNativeEvent(IEnumerable`1 triggerData) at UiPath.UIAutomationNext.Services.EventMonitorFactory.Create(IEnumerable`1 triggerData) at UiPath.UIAutomationNext.Activities.NNativeEventTrigger`1.CreateMonitor(NativeActivityContext context, IEventMonitorFactory factory, IRuntimeContext runtimeContext, Action`1 sendTrigger) at UiPath.UIAutomationNext.Activities.TriggerBase`1.StartMonitor(NativeActivityContext context, Action`1 sendTrigger) at UiPath.Platform.Triggers.TriggerBase`1.Execute(NativeActivityContext context) at UiPath.Platform.Triggers.InterruptibleTriggerBase`1.ExecuteAsInterruptibleTrigger(NativeActivityContext context) at UiPath.Platform.Triggers.InterruptibleTriggerBase`1.Execute(NativeActivityContext context) at System.Activities.NativeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Can you provide an updated version of the ApplicationEventTriggerSequence.xaml that works as expected for the provided sample?

InterceptRestAPIWithInjectJsScriptActivity.zip (1.6 MB)

InterceptRestAPIWithInjectJsScriptActivity.zip (6.1 MB)
@marian.platonov Thanks for trying it.
This exception is expected: “Invalid Trigger. Only ‘app’ attribute is allowed for ‘html’ selector.” It can’t be the default one because for most tab (html) level events, we have to monitor all tabs, and details about the tab that triggered the event should be visible in the TriggerEventArgs.
In your case, use a simple selector <html app='chrome.exe' />

I attached a workflow that works with UiAutomation 24.10.14.
Each trigger is in its own workflow and the main.xaml calls “Run Local Triggers” activity to start them all.

I first tried using 25.10.22, but I couldn’t get past UI issues that I’m going to share with the team.