Saving HTTP requests from Chrome's DevTools - google-contacts-api

I'm currently working on my Bachelor's Degree paper and I want to create an environment for software testing.
I found that the requests shown in the Network tab of Chrome's Developer tools would be very helpful for what I'm trying to develop.
So I was wondering...Is there a way of saving these kind of requests in a file on my local or to access them through Java code?

Is your goal to save the request or response data?
If you're interested in saving the responses, you could either save the entire page, or save individual requests using the network requests tab in the Chrome Inspector.

Related

How I can export data automatically in browsers dev tools network fetch?

I am working as a data analysist and I am junior too. The following is my question/problem.
I want to access some data from the requested headers from dev network tabs in browsers. How can I export those data automatically even with certain changes on latter request?
Let me explore more,
For example, I am navigating a site. Then I am going to access development tools of the browser and then I navigate to the network tab with fetch XHR, after that I want to export the response of it automatically. how can I do that?
Thank you!

How do some web pages change data without any trace of network activity?

I have seen some websites especially the ones that involve currency/cryptocurrency/stocks exchange rates, how are they able to display the latest currency exchange in the browser while also not having any trace of network activity in the browser tab?
Most likely they are using either Server-sent Events or Websockets.
For example, if you go to https://bitcointicker.co/, there are constant price updates. If you look in Chrome devtools, there are no new network requests happening. However, if you are looking at the Network tab, and click on "WS" (for websocket), there will be a single request. If you click on it, and then click on messages, you will see a stream of data.
All website now use Ajax to update content , they just update a small part of web site.

Save all XHR requests from Chrome (or other browser) Developer Tools

I'm working with a monolithic project which uses multiple servers to render data in a SPA.
In order to run this locally I use Mockoon to mock these requests/responses.
My problem is I have to create each response manually. This is tedious.
Does anyone have any experience with automating the process so I can just run through various screens on production and export the list of XHR requests with their respective responses which I can then import to Mockoon afterwards?
Workaround: Postman has a feature called 'intercept' which tracks all XHR requests (with patterns if needed) and saves them. You can then download the saved routes in JSON format.
You can also use Mockswitch recording feature which allows to record a host and creates automatic endpoints. You can find about the feature on their documentation site Record responses

Logging network tab automatically without opening it in Google Chrome

I need to log the information shown in network tab to a file. I can do it by firing network tab first and then exporting it to a file. But is it possible to run the network tab and exporting it to a file in the background automatically whenever the Chrome is opened?
Is it possible to do?
It depends on your requirement. If your extension involves DevTools, and therefore it is open, you can use the chrome.devtools.network.getHAR() method to get the network traffic. You don't need to navigate to the Network tab.
However, if you want to access the network data without DevTools being opened, this API will not work, as it's only exposed to the DevTools instance. There are a couple of possible options.
Option 1
You could use the chrome.webRequest API to intercept each request/response and append whatever data you want/can to an object. You could then use the chrome.downloads API to download the data. In your case, you could use a data URI.
var url = 'data:application/json;base64,' + btoa(data);
chrome.downloads.download({url: url, filename: 'notQuiteAHAR'json'});
I haven't tested this in practice, and I'm not too sure if you can determine when all requests are done before calling the download.
Option 2
Use the more low level chrome.debugger API, as per the comment by #wOxxOm. The debugging protocol only allows one instance of the debugger at a time, so this will only ever work if you don't have DevTools running. The API exposes a lot more than the chrome.webRequest API, but requires a bit of work to get all the data you need.
There's a repository called chrome-har-capturer, which uses the debugging protocol. Of particular interest is har.js, which uses the events found in the debugger API to manually construct the HAR. The purpose of the library is for remote debugging purposes, but I believe you can use the debugger API in an extension, and so you could probably use aspects of this repository.
As suggested by Gideon Pyzer, HAR Recorder uses chrome debug protocol to record HAR and generate a har file (without opening devtools). If you want a variation, you can fork and make changes on it.

How to grep/search ALL the data pulled by a web page

I've been using Chrome's Developer tools and it's easy (using the Network tab) to see all the data that is being pulled to build the web page that's being loaded, including the initial source data.
But how do I search/grep thru all the subsequent documents being pulled including XHR calls?
Thanks in advance!