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

[Feature] Metrics API #18071

Open
unlikelyzero opened this issue Oct 13, 2022 · 2 comments
Open

[Feature] Metrics API #18071

unlikelyzero opened this issue Oct 13, 2022 · 2 comments

Comments

@unlikelyzero
Copy link
Contributor

unlikelyzero commented Oct 13, 2022

Playwright does not currently support a native metrics API made available in puppeteer. https://pptr.dev/api/puppeteer.page.metrics/

This has been filed in a few ways:

#16711 and #590

I believe that #590 best captures the original intent of the RFE and was closed before playwright became widely adopted.

Since 2021, there have been several projects which leverage puppeteer's native metrics API and could/would switch to using playwright-core if the API became native:

nolanlawson/fuite#44
facebook/memlab#35

We are developing our own shim until this API becomes available and would be willing to take on the work on porting this API from puppeteer to playwright if necessary.

@unlikelyzero
Copy link
Contributor Author

/**
* Return a performance metric from the chrome cdp session.
* Note: Chrome-only
* @param {object} page page to attach cdpClient
* @param {String} metricName the name of the metric to be extracted
* @return {Object}
* @see {@link https://github.com/microsoft/playwright/issues/18071 Github RFE}
*/
async function getMetrics(page) {
    let client;
    client = await page.context().newCDPSession(page);
    await client.send('Performance.enable');
    const perfMetricObject = await client.send('Performance.getMetrics');
    const extractedMetric = perfMetricObject?.metrics;
    const metricObject = extractedMetric.reduce((acc, {name, value}) => {
        acc[name] = value;

        return acc;
    }, {});

    return metricObject;
}

@Fhui
Copy link

Fhui commented Dec 9, 2022

async function getMetrics(page) {
    let client;
    client = await page.context().newCDPSession(page);
    await client.send('Performance.enable');
    const perfMetricObject = await client.send('Performance.getMetrics');
    const extractedMetric = perfMetricObject?.metrics;
    const metricObject = extractedMetric.reduce((acc, {name, value}) => {
        acc[name] = value;

        return acc;
    }, {});

    return metricObject;
}

good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants