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.
Use the getResources() call and the onResourceContent
event to obtain the list of resources (documents, stylesheets, scripts, images
etc) within the inspected page. The getContent() and setContent() methods of the Resource class along with the
onResourceContentCommitted event may be used to support
modification of the resource content, e.g. by an external editor.
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.
getResources
void
chrome.experimental.devtools.inspectedWindow.getResources(, function
callback)
Undocumented.
Retrieves the list of resources from the inspected page.
Parameters
-
callback
(
optional
enumerated
Type
array of
function
)
-
Undocumented.
- A function that is called upon request completion.
-
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(array of Resource resources) {...};
-
resources
(
optional
enumerated
Type
array of
Resource
array of
paramType
paramType
)
-
Undocumented.
- The resources within the page.
-
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
onResourceAdded
chrome.experimental.devtools.inspectedWindow.onResourceAdded.addListener(function(Resource resource) {...});
Undocumented.
Fired when a new resource is added to the inspected page.
Listener parameters
-
resource
(
optional
enumerated
Resource
array of
paramType
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
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.
-
-
-
-
Extra parameters to addListener
Listener returns
onResourceContentCommitted
chrome.experimental.devtools.inspectedWindow.onResourceContentCommitted.addListener(function(Resource resource) {...});
Undocumented.
Fired when a new revision of the resource is committed (e.g. user saves an edited version of the resource in the Developer Tools).
Listener parameters
-
resource
(
optional
enumerated
Resource
array of
paramType
)
-
Undocumented.
-
Description of this parameter from the json schema.
-
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.
-
-
-
-
Extra parameters to addListener
Listener returns
Types
Resource
paramName
(
optional
enumerated
Type
array of
object
)
Undocumented.
A resource within the inspected page, such as a document, a script or an image.
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.
-
url
(
optional
enumerated
Type
array of
string
)
-
Undocumented.
- The URL of the resource.
-
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 of Resource
getContent
void
resource.getContent(, function
callback)
Undocumented.
Gets the content of the resource.
Parameters
-
callback
(
optional
enumerated
Type
array of
function
)
-
Undocumented.
- A function that is called upon request completion.
-
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(string content, string encoding) {...};
-
content
(
optional
enumerated
Type
array of
string
)
-
Undocumented.
- Content of the resource (potentially encoded).
-
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.
-
-
-
-
-
encoding
(
optional
enumerated
Type
array of
string
)
-
Undocumented.
- Empty if content is not encoded, encoding name otherwise. Currently, only base64 is supported.
-
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.
setContent
void
resource.setContent(, string
content, boolean
commit, function
callback)
Undocumented.
Sets the content of the resource.
Parameters
-
content
(
optional
enumerated
Type
array of
string
)
-
Undocumented.
- New content of the resource. Only resources with the text type are currently supported.
-
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.
-
-
-
-
-
commit
(
optional
enumerated
Type
array of
boolean
)
-
Undocumented.
- True if the user has finished editing the resource and the new content of the resource should be persisted, false if this is a minor change sent in progress of the user editing the resource.
-
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 upon request completion.
-
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 error) {...};
-
error
(
optional
enumerated
Type
array of
Resource
array of
paramType
object
)
-
Undocumented.
- Set to undefined if the operation completed successfully, describes error otherwise.
-
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.