3

I want to copy all network responses from the filtered list of requests from the network tab under Chrome's devtools.

I read about the solution of copy all requests' URLs at Multiple URLs copy in Sources/Network tab But I can't figure out how to access the decoded response body from requests.

The solution at Chrome Devtools: Save specific requests in Network Tab works, but I want a solution that only extracts responses from the filtered request list under the network tab.

Kai
  • 41
  • 2
  • I found out about "static async _copyResponse(request)" function from https://chromium.googlesource.com/chromium/src/third_party/+/master/blink/renderer/devtools/front_end/network/NetworkLogView.js?autodive=0%2F I can get a network request from devtools for devtools(https://stackoverflow.com/questions/41200450/multiple-urls-copy-in-sources-network-tab?newreg=7d6ffd5426924800842f5b4594d3cdc0): request = UI.panels.network._networkLogView._dataGrid._rootNode._flatNodes[0]._request But "UI.panels.network._networkLogView" has no function of _copyResponse. – Kai Sep 03 '19 at 04:18
  • I haven't found an answer yet. – Kai Sep 04 '19 at 06:05
  • Does this answer your question? [Multiple URLs copy in Sources/Network tab](https://stackoverflow.com/questions/41200450/multiple-urls-copy-in-sources-network-tab) – Elisha Habinsky May 08 '20 at 03:56

1 Answers1

5

Inspecting the source code of devtools reveals we need contentData() method.

The how-to-use instructions are the same as in Multiple URLs copy in Sources/Network tab.

(async () => {
  const getContent = r => r._url && !r._url.startsWith('data:') && r.contentData();
  const nodes = UI.panels.network._networkLogView._dataGrid._rootNode._flatNodes;
  const requests = nodes.map(n => n._request);
  const bowels = await Promise.all(requests.map(getContent));
  const looks = bowels.map((data, i) => {
    const r = requests[i];
    const url = r._url;
    const content = !data ? 'data is encoded inside the data url already, duh' :
      r.contentType().isTextType() ? data.content :
        Common.ContentProvider.contentAsDataURL(data.content, r.mimeType, data.encoded);
    return {url, content};
  });
  console.log(looks);
})();
wOxxOm
  • 53,493
  • 8
  • 111
  • 119