chrome.experimental.devtools.inspectedWindow.* APIs
For information on how to use experimental APIs, see the chrome.experimental.* APIs page.
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:
- The
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.
-
The evaluated code may return a value that is passed to the extension callback.
The returned value has to be a valid JSON object (i.e. may contain only
primitive JavaScript types and acyclic references to other JSON
objects).
Please observe extra care while processing the data received from the
inspected page — the execution context is essentially controlled by the
inspected page; a malicious page may affect the data being returned to the
extension.
-
The execution context of the code being evaluated includes the
Developer
Tools console API (e.g.
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.
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.
API reference: chrome.experimental.devtools.inspectedWindow
Properties
tabId
chrome.experimental.devtools.inspectedWindow.tabId
tabId
(
optional
enumerated
Type
array of
integer
)
Undocumented.
The ID of the tab being inspected. This ID may be used with chrome.tabs.* API.
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
Methods
eval
void
chrome.experimental.devtools.inspectedWindow.eval(, string
expression, function
callback)
Undocumented.
Evaluates a JavaScript expression in the context of the main frame of the inspected page. The expression must evaluate to a JSON-compliant object, otherwise an exception is thrown.
Parameters
-
expression
(
optional
enumerated
Type
array of
string
)
-
Undocumented.
- An expression to evaluate.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
callback
(
optional
enumerated
Type
array of
function
)
-
Undocumented.
- A function called when evaluation completes.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
Returns
Callback function
The callback parameter should specify a function
that looks like this:
If you specify the callback parameter, it should
specify a function that looks like this:
function(object result, boolean isException) {...};
-
result
(
optional
enumerated
Type
array of
object
)
-
Undocumented.
- The result of evaluation.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
-
isException
(
optional
enumerated
Type
array of
boolean
)
-
Undocumented.
- Set if an exception was caught while evaluating the expression
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
This function was added in version .
If you require this function, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
reload
void
chrome.experimental.devtools.inspectedWindow.reload(, string
userAgent)
Undocumented.
Reloads the inspected page, optionally setting override for the user agent string.
Parameters
-
userAgent
(
optional
enumerated
Type
array of
string
)
-
Undocumented.
- A user agent override string.
-
This parameter was added in version
.
You must omit this parameter in earlier versions,
and you may omit it in any version. If you require this
parameter, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
-
-
-
-
Returns
Callback function
The callback parameter should specify a function
that looks like this:
If you specify the callback parameter, it should
specify a function that looks like this:
function(Type param1, Type param2) {...};
This function was added in version .
If you require this function, the manifest key
minimum_chrome_version
can ensure that your extension won't be run in an earlier browser version.
Events
event name
chrome.bookmarksonEvent.addListener(function(Type param1, Type param2) {...}, Type opt_param1, Type opt_param2);
Undocumented.
A description from the json schema def of the event goes here.
Extra parameters to addListener
Listener returns