0

My code works fine in Chrome DevTools, but now I would like to move the panel of my extension from chrome debugger to my extension's popup.

In particular I have a problem with this code:

function callCommand(cmd) {
    chrome.devtools.inspectedWindow.eval(
        cmd,
        {useContentScriptContext: true},
        function (isException, result) {
            if (isException || chrome.runtime.lastError) {
                console.error('Error', cmd, result, chrome.runtime.lastError);
            }
        }
    );

Obviously the chrome debugger tool says Cannot read property 'inspectedWindow' of undefined because inspectedWindow works only in chrome devtools.

How can I implement it differently?

1
  • Why can't you just use tabs.executeScript? Oct 20, 2015 at 19:58

1 Answer 1

1

chrome.devtools API is not available outside the dedicated devtools page defined in manifest.json, and the error message implies that. You can only reimplement the functionality you need differently or drop it from the extension.

For example, if you want to execute some code in the context of the page, inject a <script> element with the code: Building a Chrome Extension - Inject code in a page using a Content script

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.