How to capture network requests from a page

Capturing network requests from a page can be very helpful in understanding the functionality of a page, and what resources that they are loading. This can be done using your automation and some simple code.

# Getting started


To get started, create a new automation.

# Capturing network requests


As the first step in your automation, add a Go to page step. Then, add a Write Javascript step to your automation. The following will return an array of arrays that contains the entryType and the name of the entries.

var resources = [];

// Grab the resources
const entries = window.performance.getEntriesByType("resource");

// Loop through the PerformanceEntry objects that were returned, add these to the `resources` array.
entries.forEach((entry) => {
    resources.push([entry.entryType, entry.name]);
})

// Return the data
return resources;

The window.performance.getEntriesByType("resource") will return an array of PerformanceEntry (opens new window) objects that can be used to access the resources. Check out the developer documentation for more information on the information that can be accessed using this function: developer.mozilla.org (opens new window).

You'll find the data retrieved in the code-data data token. This can be used in later steps of your automation, for example, written to a Google Sheet using the Write data to a Google Sheet step.

# Testing your workflow


To test, ensure that you have a URL set within the "Go to page" step. Next, you can use the Display a message step, or the Write data to a Google Sheet step to output the code-data data token that should contain the data regarding the network requests that have been captured.

# Wrapping up


These are numerous reasons why you may wish to capture network requests on a third-party website, including integration testing, security testing, or even learning and development opportunities. Axiom.ai gives you the ability to do this with ease using just two steps. We are excited to see what you do with this - let us know over in our community (opens new window).