Coverage class

Coverage gathers information about parts of JavaScript and CSS that were used by the page.

An example of using JavaScript and CSS coverage to get percentage of initially executed code:

// Enable both JavaScript and CSS coverage
await Future.wait(
    [page.coverage.startJSCoverage(), page.coverage.startCSSCoverage()]);
// Navigate to page
await page.goto('https://example.com');
// Disable both JavaScript and CSS coverage
var jsCoverage = await page.coverage.stopJSCoverage();
var cssCoverage = await page.coverage.stopCSSCoverage();
var totalBytes = 0;
var usedBytes = 0;
var coverage = [...jsCoverage, ...cssCoverage];
for (var entry in coverage) {
  totalBytes += entry.text.length;
  for (var range in entry.ranges) {
    usedBytes += range.end - range.start - 1;
  }
}
print('Bytes used: ${usedBytes / totalBytes * 100}%');

Constructors

Coverage(DevTools devTools)

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
startCSSCoverage({bool? resetOnNavigation}) Future<void>
Parameters
startJSCoverage({bool? resetOnNavigation, bool? reportAnonymousScripts}) Future<void>
Parameters:
stopCSSCoverage() Future<List<CoverageEntry>>
Returns a Future that resolves to the array of coverage reports for all stylesheets
stopJSCoverage() Future<List<CoverageEntry>>
Returns a Future that resolves to the array of coverage reports for all scripts
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited