I'm trying to get all the network requests when a page is accessed and store them into an array.
My code looks like this:
await page.setRequestInterceptionEnabled(true);
page.on('request', request => {
if(request.url) {
var networkRequests = request.url;
var networkArray = [];
for (var i = 0; i < networkRequests; i++) {
networkArray.push(networkRequests[i]);
}
console.log(networkArray);
console.log(typeof networkArray);
request.continue();
} else {
request.abort();
}
});
await page.goto('http://www.example.com', {waitUntil: 'networkidle'});
I find that the problem is with the request.continue()
. It creates several iterations for each fetched request, and for each iteration it shows that request and returns it as string.
That means that I end up with several strings.
The problem is that I couldn't managed to insert all those strings into one array, so I can make use of them lately. I tried several for loops but didn't succeed.
A quick fix has been found in the meantime: