experimental.webInspector.audits
For information on how to use experimental APIs, see the chrome.experimental.* APIs page.
Use the experimental.webInspector.audits
module to add new audit
categories and rules to WebInspector's Audit panel.
See WebInspector API summary for
general introduction to using WebInspector API.
Notes
Each audit category is represented by a line on Select audits to run
screen in the Audits panel. The following example adds a category named
Readability:
var category = webInspector.audits.addCategory("Readability", 2);
If the category's checkbox is checked, the onAuditStarted
event of
that category will be fired when user clicks the Run button.
The event handler in your extension receives AuditResults
as an argument and should add one or more results using addResult()
method. This may be done asynchronously, i.e. after the handler returns. The
run of the category is considered to be complete once the extension adds the
number of results declared when adding the category with
experimental.webInspector.audits.addCategory()
or
calls AuditResult's done()
method.
The results may include additional details visualized as an expandable
tree by the Audits panel. You may build the details tree using
createResult()
and addChild()
methods. The child node
may include specially formatted fragments created by
auditResults.snippet()
or auditResults.url()
.
The following example adds a handler for onAuditStarted event that creates two
audit results and populates one of them with the additional details:
category.onAuditStarted.addListener(function(results) {
var details = results.createResult("Details...");
var styles = details.addChild("2 styles with small font");
var elements = details.addChild("3 elements with small font");
results.addResult("Font Size (5)",
"5 elements use font size below 10pt",
results.Severity.Severe,
details);
results.addResult("Contrast",
"Text should stand out from background",
results.Severity.Info);
});
The audit result tree produced by the snippet above will look like this:
API reference: experimental.webInspector.audits
Properties
getLastError
chrome.extensionlastError
Methods
addCategory
AuditCategory
experimental.webInspector.audits.addCategory(, string
displayName, number
resultCount)
Undocumented.
Adds an audit category.
Parameters
-
displayName
(
optional
enumerated
Type
array of
string
)
-
Undocumented.
- A display name for the category
-
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.
-
-
-
-
-
resultCount
(
optional
enumerated
Type
array of
number
)
-
Undocumented.
- The expected number of audit results in the category.
-
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
-
paramName
-
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.
-
-
-
-
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) {...});
Undocumented.
A description from the json schema def of the event goes here.
Types
AuditCategory
paramName
(
optional
enumerated
Type
array of
object
)
Undocumented.
A set of audit rules
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.
Events of AuditCategory
onAuditStarted
auditCategory.onAuditStarted.addListener(function(AuditResults results) {...});
Undocumented.
Fired when the audit is started, if the category is enabled -- the extension is expected to begin executing audit rules.
Parameters
-
results
-
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.
-
-
-
-
FormattedValue
paramName
(
optional
enumerated
Type
array of
object
)
Undocumented.
A value returned from one of the formatters (an URL, code snippet etc), to be passed to createResult or addChild
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.
AuditResults
paramName
(
optional
enumerated
Type
array of
object
)
Undocumented.
A collection of audit results for current run of the audit category
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.
-
Severity
-
Undocumented.
- A class that contains possible values for audit result severities.
-
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.
-
-
-
-
-
text
(
optional
enumerated
Type
array of
string
)
-
Undocumented.
- The contents of the node.
-
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.
-
-
-
-
-
children
-
Undocumented.
- Children of this node.
-
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.
-
-
-
-
-
expanded
(
optional
enumerated
Type
array of
boolean
)
-
Undocumented.
- Whether the node is expanded by default.
-
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 AuditResults
addResult
AuditCategory
auditResults.addResult(, string
displayName, string
description, AuditResultSeverety
severity, AuditResultNode
details)
Undocumented.
Adds an audit category.
Parameters
-
displayName
(
optional
enumerated
Type
array of
string
)
-
Undocumented.
- A concise, high-level description of audit rule result
-
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.
-
-
-
-
-
description
(
optional
enumerated
Type
array of
string
)
-
Undocumented.
- A detailed description of what the displayName means
-
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.
-
-
-
-
-
severity
-
Undocumented.
- The expected number of audit results in the category.
-
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.
-
-
-
-
-
details
-
Undocumented.
- A subtree that appears under added result that may provide additional details on the violations found
-
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
-
paramName
-
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.
-
-
-
-
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.
createResult
AuditResultNode
auditResults.createResult(, string or FormattedValue
content ...)
Undocumented.
Creates a result node that may be user as details parameters to addResult
Parameters
-
content ...
(
optional
enumerated
Type
array of
string or FormattedValue
)
-
Undocumented.
- Either string or formatted values returned by one of AuditResult formatters (url, snippet etc)
-
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
-
paramName
-
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.
-
-
-
-
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.
done
AuditCategory
auditResults.done(, string
displayName, number
resultCount)
Undocumented.
Signals the WebInspector Audits panel that the run of this category is over. Normally the run completes automatically when a number of added top-level results is equal to that declared when AuditCategory was created.
Parameters
-
displayName
(
optional
enumerated
Type
array of
string
)
-
Undocumented.
- A display name for the category
-
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.
-
-
-
-
-
resultCount
(
optional
enumerated
Type
array of
number
)
-
Undocumented.
- The expected number of audit results in the category.
-
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
-
paramName
-
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.
-
-
-
-
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.
snippet
FormattedValue
auditResults.snippet(, string
text)
Undocumented.
Render passed text as a code snippet in the Audits panel
Parameters
-
text
(
optional
enumerated
Type
array of
string
)
-
Undocumented.
- Snippet text
-
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
-
paramName
-
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.
-
-
-
-
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.
url
FormattedValue
auditResults.url(, string
href, string
displayText)
Undocumented.
Render passed value as an URL in the Audits panel
Parameters
-
href
(
optional
enumerated
Type
array of
string
)
-
Undocumented.
- An URL that will appear as href value on resulting link
-
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.
-
-
-
-
-
displayText
(
optional
enumerated
Type
array of
string
)
-
Undocumented.
- A text that will appear to user
-
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
-
paramName
-
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.
-
-
-
-
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.
AuditResultNode
paramName
(
optional
enumerated
Type
array of
object
)
Undocumented.
A node in the audit result trees. Displays some content and optionally has children node
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.
-
expanded
(
optional
enumerated
Type
array of
boolean
)
-
Undocumented.
- If set, the subtree will always be expanded
-
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 AuditResultNode
addChild
AuditResultNode
auditResultNode.addChild(, string or FormattedValue
content ...)
Undocumented.
Adds another child node to this node
Parameters
-
content ...
(
optional
enumerated
Type
array of
string or FormattedValue
)
-
Undocumented.
- Either string or formatted values returned by one of AuditResult formatters (url, snippet etc)
-
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
-
paramName
-
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.
-
-
-
-
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.
AuditResultSeverity
paramName
(
optional
enumerated
Type
array of
object
)
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.
-
Info
(
optional
enumerated
Type
array of
string
)
-
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.
-
-
-
-
-
Warning
(
optional
enumerated
Type
array of
string
)
-
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.
-
-
-
-
-
Severe
(
optional
enumerated
Type
array of
string
)
-
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.
-
-
-
-