R.Bianchi
R.Bianchi

Reputation: 27

Alternative to 'inspectedWindow' (not for chrome devtools)

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?

Upvotes: 0

Views: 278

Answers (1)

woxxom
woxxom

Reputation: 73596

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

Upvotes: 1

Related Questions