2021-01-07 11:46:05 -08:00
|
|
|
# class: ChromiumCoverage
|
2021-01-07 16:12:25 -08:00
|
|
|
* langs: js
|
2021-01-07 11:46:05 -08:00
|
|
|
|
|
|
|
Coverage gathers information about parts of JavaScript and CSS that were used by the page.
|
|
|
|
|
2021-03-26 18:47:16 +01:00
|
|
|
An example of using JavaScript coverage to produce Istanbul report for page load:
|
2021-01-07 11:46:05 -08:00
|
|
|
|
|
|
|
```js
|
|
|
|
const { chromium } = require('playwright');
|
|
|
|
const v8toIstanbul = require('v8-to-istanbul');
|
|
|
|
|
|
|
|
(async() => {
|
|
|
|
const browser = await chromium.launch();
|
|
|
|
const page = await browser.newPage();
|
|
|
|
await page.coverage.startJSCoverage();
|
|
|
|
await page.goto('https://chromium.org');
|
|
|
|
const coverage = await page.coverage.stopJSCoverage();
|
|
|
|
for (const entry of coverage) {
|
|
|
|
const converter = new v8toIstanbul('', 0, { source: entry.source });
|
|
|
|
await converter.load();
|
|
|
|
converter.applyCoverage(entry.functions);
|
|
|
|
console.log(JSON.stringify(converter.toIstanbul()));
|
|
|
|
}
|
|
|
|
await browser.close();
|
|
|
|
})();
|
|
|
|
```
|
|
|
|
|
|
|
|
## async method: ChromiumCoverage.startCSSCoverage
|
|
|
|
|
|
|
|
Returns coverage is started
|
|
|
|
|
|
|
|
### option: ChromiumCoverage.startCSSCoverage.resetOnNavigation
|
|
|
|
- `resetOnNavigation` <[boolean]>
|
|
|
|
|
|
|
|
Whether to reset coverage on every navigation. Defaults to `true`.
|
|
|
|
|
|
|
|
## async method: ChromiumCoverage.startJSCoverage
|
|
|
|
|
|
|
|
Returns coverage is started
|
|
|
|
|
2021-01-12 12:14:27 -08:00
|
|
|
:::note
|
|
|
|
Anonymous scripts are ones that don't have an associated url. These are scripts that are dynamically created
|
2021-01-07 11:46:05 -08:00
|
|
|
on the page using `eval` or `new Function`. If [`option: reportAnonymousScripts`] is set to `true`, anonymous scripts
|
|
|
|
will have `__playwright_evaluation_script__` as their URL.
|
2021-01-12 12:14:27 -08:00
|
|
|
:::
|
2021-01-07 11:46:05 -08:00
|
|
|
|
|
|
|
### option: ChromiumCoverage.startJSCoverage.resetOnNavigation
|
|
|
|
- `resetOnNavigation` <[boolean]>
|
|
|
|
|
|
|
|
Whether to reset coverage on every navigation. Defaults to `true`.
|
|
|
|
|
|
|
|
### option: ChromiumCoverage.startJSCoverage.reportAnonymousScripts
|
|
|
|
- `reportAnonymousScripts` <[boolean]>
|
|
|
|
|
|
|
|
Whether anonymous scripts generated by the page should be reported. Defaults to `false`.
|
|
|
|
|
|
|
|
## async method: ChromiumCoverage.stopCSSCoverage
|
|
|
|
- returns: <[Array]<[Object]>>
|
|
|
|
- `url` <[string]> StyleSheet URL
|
|
|
|
- `text` <[string]> StyleSheet content, if available.
|
|
|
|
- `ranges` <[Array]<[Object]>> StyleSheet ranges that were used. Ranges are sorted and non-overlapping.
|
|
|
|
- `start` <[int]> A start offset in text, inclusive
|
|
|
|
- `end` <[int]> An end offset in text, exclusive
|
|
|
|
|
|
|
|
Returns the array of coverage reports for all stylesheets
|
|
|
|
|
2021-01-12 12:14:27 -08:00
|
|
|
:::note
|
|
|
|
CSS Coverage doesn't include dynamically injected style tags without sourceURLs.
|
|
|
|
:::
|
2021-01-07 11:46:05 -08:00
|
|
|
|
|
|
|
## async method: ChromiumCoverage.stopJSCoverage
|
|
|
|
- returns: <[Array]<[Object]>>
|
|
|
|
- `url` <[string]> Script URL
|
|
|
|
- `scriptId` <[string]> Script ID
|
|
|
|
- `source` <[string]> Script content, if applicable.
|
|
|
|
- `functions` <[Array]<[Object]>> V8-specific coverage format.
|
|
|
|
- `functionName` <[string]>
|
|
|
|
- `isBlockCoverage` <[boolean]>
|
|
|
|
- `ranges` <[Array]<[Object]>>
|
|
|
|
- `count` <[int]>
|
|
|
|
- `startOffset` <[int]>
|
|
|
|
- `endOffset` <[int]>
|
|
|
|
|
|
|
|
Returns the array of coverage reports for all scripts
|
|
|
|
|
2021-01-12 12:14:27 -08:00
|
|
|
:::note
|
|
|
|
JavaScript Coverage doesn't include anonymous scripts by default. However, scripts with sourceURLs are
|
2021-01-07 11:46:05 -08:00
|
|
|
reported.
|
2021-01-12 12:14:27 -08:00
|
|
|
:::
|