From 80d4717057c16dba9ff2e629b85022603252b031 Mon Sep 17 00:00:00 2001
From: "caseq@google.com"
+Use
+See DevTools APIs summary for
+general introduction to using Developer Tools APIs.
+
+The 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.
+Notes
+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.
+
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:
+eval()
does not
+use an isolated world for the code being evaluated, so the JavaScript state
+of the inspected window is accessible to the code.
+inspect()
, $0
etc).
+
+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.
+
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. +
-- cgit v1.1