Use `chrome.devtools.panels.create()` in Chrome Extension content script

ぃ、小莉子 提交于 2019-12-14 03:57:03

问题


I have this in a content-script:

  chrome.devtools.panels.create('Suman Extension Page Controls',
  'icon.png',
  'devtools-panel.html',
  function (panel) {
    console.log('my devtools panel.');

  });

however, I get this error:

Uncaught TypeError: Cannot read property 'panels' of undefined

I tried adding "devtools" to the permissions array in my manifest.json file, but that's not allowed.

Is there a way to use the devtools API from a content script? How do I dynamically add panels to DevTools on a random webpage?


回答1:


It's incorrect to use it from the content scripts, from the documentation:

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

You need to create separate html file, then set it to the devtools_page property in your manifest. And after that, you can load your scripts in this html file and create panel from here.

Good example of extension, which is does this - React Dev Tools.



来源:https://stackoverflow.com/questions/48755724/use-chrome-devtools-panels-create-in-chrome-extension-content-script

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