Access response payload/data from within a chrome extension
Asked Answered
I

2

10

I am working on a project where it is required to track requests "ajax ones" from certain site, access response payload for some of those requests and act upon them.

So far i managed to track requests and access their headers using the webRequest api, the only problem is that i can't find anyway to access the actual data within those responses.

Is it even possible?.

Please feel free to post any ideas or references that could help.

Thanks and have a nice day.


EDIT:

An example of what iam looking for is the response tab in the network panel which is part of chrome's developer tools.

Impanel answered 14/1, 2013 at 19:59 Comment(0)
C
13

Network Panel is a HTML representation of HAR(HTTP Archive format) Log. You can trace each element of the network panel using devtools.network API.

You can refer to following code where TCP Connection time is being traced as a reference to get started using devtools.network API and HAR Log.

manifest.json

Register devtools.html for tracing network panel events

{
    "name": "Network Demo",
    "description": "This is a sample for API's available for Network",
    "devtools_page": "devtools.html",
    "manifest_version": 2,
    "version": "2"
}

devtools.html

Register devtools.js to comply with CSP.

<html>
    
    <head>
        <script src="devtools.js"></script>
    </head>
    
    <body></body>

</html>

devtools.js

req in the following code returns HAR Log and you can use it for reading content you need; I have used the HAR for TCP Connection time here

chrome.devtools.network.onRequestFinished.addListener(function(req) {
    // Displayed sample TCP connection time here
   console.log(req.timings.connect);
});

References

Compander answered 15/1, 2013 at 12:28 Comment(1)
is "devtools.js" but not "devtool.js".can't EditFresher
B
2

The devtools.network API only works if the Developer Tools window is open. For everyday browsing there is no way to access response data. There is a feature request open which discusses reading/editing the response body.

Bibliographer answered 2/10, 2013 at 21:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.