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

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

Related

Access to Restricted data types and implement in development environment

We are developing application that needs write access to restricted data types. And looks like Google has stopped taking new request for whitelisting apps.
https://developers.google.com/fit/android/data-types#restricted_data_types
Note: Google has temporarily stopped taking new requests to write to restricted data types. We are updating our policy and process for reviewing requests and will update this documentation again when we resume.
Does anyone from Google have any idea when they will resume it?
Also: Is there a way to implement/write restricted data in development environment or debug build without whitelisting, and whitelist app before going to production?
There is no timeline yet for when this will be available.
(Source: I work on Google Fit)

Saving HTTP requests from Chrome's DevTools

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.

Can google chrome headless browser be used to serve PDFs to end users

I am looking to use the google chrome headless browser's 'print to pdf' functionality to replace an existing way (using iText) to generate PDFs.
Is this a feasible solution considering the number of concurrent calls that would need to be processed is unknown?
Is headless browser's print to pdf functionality used in production for enterprise solutions to generate PDFs/screenshots or is it mainly meant for testing and development environments?
If processing multiple concurrent calls from a single machine would be an issue, would a serverless solution based on AWS lambda be a good way to approach this because of the scalability and the ability to do parallel processing?
I used the lambda functions for creating PDF files and it works fine. Scalability and parallel process also works as well because it is AWS lambdas.
But while I creating the working solution a got a lot of problems.
First of all, I used AWS API Gateway as a trigger for the lambda and I got a 30-sec timeout for the API request. This means time was limited.
My first solution was usage "chrome-aws-lambda" and "puppeteer-core" nodeJS libraries.
The very slow solution, if be honest. And very painful from the architecture side.
User UI -> request to back for PDF -> lambda function run the headless browser -> [ headless chrome start -> open some page -> request to the back for some data] -> wait for loading -> create snapshot -> response with PDF
Then I tried some libraries and stoped on "dynamic-html-pdf". This lib uses "handlebars" template and "html-pdf" lib as engine. If you have not some dynamic data on the page (f.e. dynamic list of items or some if statements) - you can use "html-pdf" only.

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.

Google Drive Live API: Server Export of Collaboration Document

I have a requirement to build an application with the following features:
Statistical and Source data is presented on simple HTML pages
Some missing Source data can be added from that HTML page ( data will be both exact numerical values and discriptive text )
Some new Source data can be added from those pages
Confirmed and verified data will NOT be editable via the HTML interface
Data is stored and made continuously available via the HTML interface
Periodically the data added/changed from the interface needs to be pulled back into the source data - but in a VERY controlled way. All data changes and submissions will need verification and checking - and some will trigger re-runs of models ( some of which take hours to run ).
In terms of overview architecture I have:
Large DB that stores and manages the data - this is designed for import process's and analysis. It is not ideal for web presentation or interface
Code servers that manipulate the data for imports and analysis
Frontend server that works as a proxy to add layer of security to S3
Collection of generated html files on S3 presenting the data required
Before reading about the Google Drive Realtime API my rough plan was to simply serialize data from the HTML interface and post to S3. The import server scripts would then check for new information, grab it, check it, log it and process it into the main data set.
That basic process however would mean that once changes were submitted from the web page - they would be lost from the users view until they had been processed by the backend.
With the Google Drive Realtime API it would appear I could get the best of both worlds.
However for the above to work I would need to be able to access the Collaboration Document in code from the code servers and export the data.
The Realtime API gives javascript access to Export and hand off to a function - however in my use case I want to automate the Export from the Collaboration Document.
The Google Drive SDK does not as far as I can see give any hints on downloading/exporting a file of type "Collaboration File".
What "non-browser-user" triggered methods are there for interfacing with the Collaboration Documents and exporting them?
David
Server-side export is not supported right now. What you could do is save the realtime model to a regular drive file, and read from that using the standard Drive API. See https://developers.google.com/drive/realtime/models-files for some discussion on different ways to setup interactions between realtime models and Drive Files.