chrome.experimental.devtools.audits
Description: |
Use the chrome.experimental.devtools.audits API to add new audit categories to the Developer Tools' Audit panel.
|
Availability: |
Experimental only (see How to use experimental APIs).
|
See DevTools APIs summary for general introduction to using Developer Tools APIs.
Overview
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 = chrome.experimental.devtools.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
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 the
createResult()
and addChild()
methods. The child node
may include specially formatted fragments created by the
auditResults.createSnippet()
and auditResults.createURL()
methods.
Examples
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:
You can find more examples that use this API in Samples.
Summary
Types | |
---|---|
AuditCategory | |
FormattedValue | |
AuditResults | |
AuditResultNode | |
AuditResultSeverity | |
Methods | |
addCategory −
AuditCategory
chrome.experimental.devtools.audits.addCategory(string displayName, double resultCount)
|
Types
AuditCategory
events | |||||||||
---|---|---|---|---|---|---|---|---|---|
addListener
onAuditStarted.addListener(function callback)
|
FormattedValue
AuditResults
properties | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AuditResultSeverity | Severity | A class that contains possible values for the audit result severities. | |||||||||||||
string | text | The contents of the node. | |||||||||||||
array of AuditResultNode | (optional) children | Children of this node. | |||||||||||||
boolean | (optional) expanded | Whether the node is expanded by default. | |||||||||||||
methods | |||||||||||||||
addResult
AuditResults.addResult(string displayName, string description, AuditResultSeverity severity, AuditResultNode details)
Adds an audit result. The results are rendered as bulleted items under the audit category assoicated with the
| |||||||||||||||
createResult
AuditResultNode
AuditResults.createResult(string or FormattedValue content)
Creates a result node that may be used as the
| |||||||||||||||
done
AuditResults.done()
Signals the DevTools Audits panel that the run of this category is over. The audit run also completes automatically when the number of added top-level results is equal to that declared when AuditCategory was created. | |||||||||||||||
createURL
FormattedValue
AuditResults.createURL(string href, string displayText)
Render passed value as a URL in the Audits panel.
| |||||||||||||||
createSnippet
FormattedValue
AuditResults.createSnippet(string text)
Render passed text as a code snippet in the Audits panel.
|
AuditResultNode
properties | ||||||
---|---|---|---|---|---|---|
boolean | expanded | If set, the subtree will always be expanded. | ||||
methods | ||||||
addChild
AuditResultNode
AuditResultNode.addChild(string or FormattedValue content)
Adds a child node to this node.
|
AuditResultSeverity
properties | ||
---|---|---|
string | Info | |
string | Warning | |
string | Severe |
Methods
addCategory
AuditCategory
chrome.experimental.devtools.audits.addCategory(string displayName, double resultCount)
Adds an audit category.
Parameters | ||
---|---|---|
string | displayName | A display name for the category. |
double | resultCount | The expected number of audit results in the category. |