Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report CSS and JS coverage #727

Open
macbre opened this issue Jan 22, 2019 · 1 comment
Open

Report CSS and JS coverage #727

macbre opened this issue Jan 22, 2019 · 1 comment
Labels
Chrome-headless Tasks related with migration from PhantomJS to Puppeteer's headless Chrome new metric
Milestone

Comments

@macbre
Copy link
Owner

macbre commented Jan 22, 2019

https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#class-coverage

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 Promise.all([
  page.coverage.startJSCoverage(),
  page.coverage.startCSSCoverage()
]);
// Navigate to page
await page.goto('https://example.com');
// Disable both JavaScript and CSS coverage
const [jsCoverage, cssCoverage] = await Promise.all([
  page.coverage.stopJSCoverage(),
  page.coverage.stopCSSCoverage(),
]);
let totalBytes = 0;
let usedBytes = 0;
const coverage = [...jsCoverage, ...cssCoverage];
for (const entry of coverage) {
  totalBytes += entry.text.length;
  for (const range of entry.ranges)
    usedBytes += range.end - range.start - 1;
}
console.log(`Bytes used: ${usedBytes / totalBytes * 100}%`);
@macbre macbre added this to the v2.0 - headless Chromium milestone Jan 22, 2019
@gmetais
Copy link
Contributor

gmetais commented Jan 22, 2019

Amazing 😮

@macbre macbre added the Chrome-headless Tasks related with migration from PhantomJS to Puppeteer's headless Chrome label Aug 25, 2020
@macbre macbre modified the milestones: Roadmap, v2.1 Oct 26, 2020
@macbre macbre modified the milestones: v2.1, v2.2 Jan 9, 2021
@macbre macbre modified the milestones: v2.2, Roadmap Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Chrome-headless Tasks related with migration from PhantomJS to Puppeteer's headless Chrome new metric
Projects
None yet
Development

No branches or pull requests

2 participants