Why is chrome.devtools.network “undefined”?

强颜欢笑 提交于 2019-12-03 17:06:47

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/12689239/why-is-chrome-devtools-network-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!