Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is chrome.devtools.network "undefined"?

I'm trying to create an extension that logs all network events. This is the code:

Manifest.json:

{
  "name": "My extension",
  "version" : "1.0",
  "background": {
    "scripts": ["background.js"],
    "persistent": true
  },
 "devtools_page": "devtools.html",
 "browser_action": {
    "default_title": "Get it",
    "default_icon" : "icon.png"
  },
  "manifest_version": 2
}

background.js:

chrome.devtools.network.onRequestFinished.addListener(function(request) {});

What's the problem? I tried a lot of things, it doesn't seem like any scripts that I link in devtools.html is getting picked up at all. No logs, no nothing. Only the background.js is doing something, and it doesn't seem to support chrome.devtools ?

like image 455
Blub Avatar asked Oct 02 '12 11:10

Blub


People also ask

Why does Chrome console say undefined?

If a function does not use a return statement or an empty return statement with no value, JavaScript automatically returns undefined.

How do I use Chrome Dev Tools Network?

To access this feature in Chrome, simply open the developer tools (command-option-I or command-option-J on a Mac) and select the Network option from the drop-down menu at the top. One last important thing to note: Chrome will only show Network requests that happen while the Network panel is open.

How do I fix dev tools in Chrome?

# Open the Issues tab Open DevTools. Click the Go to Issues button in the yellow warning bar. Alternatively, select Issues from the More tools menu. Once you're on the Issues tab, click the Reload page button if necessary.

What is Network in DevTools?

The Network view allows you to see and analyze the network requests that make up each individual page load within a single user's session. You can use this view to investigate the causes of slow pages and identify performance bugs.


1 Answers

chrome.devtools.network is only available within a devtools page. From the documentation of the devtools API (third list item):

The chrome.devtools.* API modules are available only to the pages loaded within the Developer Tools window. Content scripts and other extension pages do not have these APIs. Thus, the APIs are available only through the lifetime of the Developer Tools window.

If you need the information in the background page, have a look at this answer (full code included) for setting up a communication channel: Chrome Devpanel Extension Communicating with Background Page.

like image 134
Rob W Avatar answered Oct 04 '22 10:10

Rob W