Reputation:
So here is what I am trying to do. I want to save all the HTTP (content+request+response) while I am using google chrome. I found a way to this using network tool (in developer tool), where I can download everything manually.
Now I want to automate this whole process so I don't need to do any manual thing. I thought we can do this by writing a simple Chrome Extension using devtools.network
API.
chrome.devtools.network.onRequestFinished.addListener(
function(request) {
//dosomething
});
But I am kind lost here I never did the Chrome Extension development before. I made a simple manifest.json
file:
{
"manifest_version": 2,
"name": "My extension",
"version" : "1.0",
"background": {
"scripts": ["devtools.js"],
"persistent": true
},
"devtools_page": "devtools.html",
"browser_action": {
"default_title": "Get it",
"default_icon" : "icon.png"
}
}
and pasted the first code snippet in devtools.js
, but it is giving me an error:
network not defined
Am I on the right track? If so, what I am doing wrong with my code?
Upvotes: 5
Views: 2369
Reputation: 77561
From "Extending DevTools":
The
chrome.devtools.*
API modules are available only to the pages loaded within the DevTools window. Content scripts and other extension pages do not have these APIs. Thus, the APIs are available only through the lifetime of the DevTools window.
So you can use this in devtools.html
as long as it's opened, but not in background.
Alternatively, you can use chrome.debugger
API, which works as long as Dev Tools are not opened. Do note it's a pretty low-level API with little documentation.
Since, judging from your other questions, your goal is to automate the process - it's probably a better path (since there is no automated way to open a page with Dev Tools enabled as far as I know). The debugger
API can replicate what Dev Tools do, but only one tool can be attached to a page at a time - for that reason, . debugger
stops working if Dev Tools are invoked
EDIT: since Chrome 63 multiple debugger clients are supported by Chrome, making it possible to attach both Dev Tools and chrome.debugger
at the same time.
Upvotes: 4