A question that is being asked more frequently is how does my website or component affect the web browser (chrome)? So what metrics can we bring about from chrome to show the end user?
Suggested Solution (optional)
Fortunately there is CDP API that can perform this action, which is the performance API. It works by:
Calling Performance.enable
Running the some k6 browser APIs
Calling either Performance.getMetrics to retrieve the metrics
// @ts-check
import { test, chromium } from '@playwright/test';
test('nav_to_test.k6.io', async () => {
const browser = await chromium.launch()
const context = await browser.newContext()
const page = await context.newPage()
const client = await page.context().newCDPSession(page);
client.send('Performance.enable');
await page.goto('https://test.k6.io', {waitUntil: 'networkidle'});
// Requires some interaction to bring about INP and FID Web Vitals
await page.locator('a[href="/news.php"]').click();
const result = await client.send('Performance.getMetrics');
console.log(result.metrics);
await page.close({ runBeforeUnload: true })
await browser.close()
});
In Playwright and Puppeteer, there ins't a dedicated API to perform such an action, instead they allow the use of CDPSession which can be used to run raw CDP requests. It's not clear what the security implications are of opening up a CDPSession like this.
The options for us are:
Create a dedicated API to retrieve these performance metrics, basically a wrapper around the Performance CDP API.
Implement CDPSession but only allow some of the API calls (e.g. only the Performance ones) to be made through it until it's clear what security implications it may have.
Already existing or connected issues / PRs (optional)
Feature Description
A question that is being asked more frequently is how does my website or component affect the web browser (chrome)? So what metrics can we bring about from chrome to show the end user?
Suggested Solution (optional)
Fortunately there is CDP API that can perform this action, which is the performance API. It works by:
Performance.enable
Performance.getMetrics
to retrieve the metricsPerformance.disable
to end it.This will result in the following:
Here's a PW script that can be used to test this:
In Playwright and Puppeteer, there ins't a dedicated API to perform such an action, instead they allow the use of CDPSession which can be used to run raw CDP requests. It's not clear what the security implications are of opening up a CDPSession like this.
The options for us are:
Performance
CDP API.Already existing or connected issues / PRs (optional)
No response