chrome.experimental.devtools.inspectedWindow.* APIs

Use chrome.experimental.devtools.inspectedWindow to interact with the inspected window: obtain tab ID for the inspected page, evaluate the code in the context of inspected window, reload the page.

See DevTools APIs summary for general introduction to using Developer Tools APIs.

Notes

The tabId property provides tab identifier that may be used with the chrome.tabs.* API calls. However, please note that chrome.tabs.* API is not exposed to the Developer Tools extension pages due to security considerations — you will need to pass the tab ID to the background page and invoke the chrome.tabs.* API functions from there.

The eval() provides the ability for extensions to execute JavaScript code in the context of the main frame of the inspected page. This function is different from chrome.tabs.executeScript() in the following aspects:

Important: Due to the security considerations explained above, chrome.tabs.executeScript() is the preferred way for an extension to access DOM data of the inspected page in cases where the access to JavaScript state of the inspected page is not required.

The reload() may be used to reload the inspected page. Additionally, a user agent string may be specifcied, which will cause Chrome to use the given string in the User-Agent HTTP header while fetching the page and its resources, and return it to the scripts running in that page.

Examples

The following code checks for the version of jQuery used by the inspected page:

chrome.experimental.devtools.inspectedWindow.eval(
    "jQuery.fn.jquery",
     function(result, isException) {
       if (isException)
         console.log("the page is not using jQuery");
       else
         console.log("The page is using jQuery v" + result);
     }
);

You can find more examples that use Developer Tools APIs in Samples.