I know that I can get all HTTP Requests in DevTool, but now I want to get them in a chrome extension. Which API can do this job?
            Asked
            
        
        
            Active
            
        
            Viewed 9,136 times
        
    2 Answers
3
            
            
        You would be looking at webRequest API with an event filter based on the tab ID.
Something like this (requires "webRequest" permission and "<all_urls>" host permission):
chrome.webRequest.onBeforeRequest.addListener(
  function(details) {
    // Do something with the details
  },
  {tabId: /* ... */, urls: "<all_urls>"}
);
P.S. I saw your other question regarding resources; note that you can further filter requests by type, e.g. "stylesheet"
 
    
    
        Xan
        
- 74,770
- 16
- 179
- 206
- 
                    I assume this will not catch requests which happened before the listener was added? If the OP intends to use this from a page-action button, it may not yield the desired results. – levi Mar 17 '15 at 16:41
- 
                    @levi Technically, that's not specified in the question. But neither do DevTools (normally) log network requests until opened. You need to be ready for this. – Xan Mar 17 '15 at 16:45
0
            
            
        chrome.webRequest is helpful but it doesn't let you read the response body in Chrome. I have a solution for reading the body here: https://stackoverflow.com/a/67390377/1226799
 
    
    
        Justin Harris
        
- 1,969
- 2
- 23
- 33
