playwright-performance is a plugin for Playwright that enables detailed performance analysis of end-to-end test flows, including UI, API, or hybrid scenarios. It measures the 'apparent response time' of key user procedures within your application, helping identify bottlenecks and areas for optimization. The current stable version is 2.0.6, with recent updates introducing HTML chart generation. The library maintains an active release cadence, with a major breaking change in version 2.x.x simplifying its integration model. Its key differentiator is the seamless integration into Playwright's `test.extend` fixture system, allowing developers to easily add performance sampling to existing tests without significant refactoring, and providing configurable output options for results.
npm install playwright-performanceVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to extend Playwright's `test` object with performance fixtures, record startup times for multiple URLs, and assert on individual sample durations within an extended test.
Migrate to the new ESM-first import syntax (`import extendPlaywrightPerformance, { ... } from 'playwright-performance'`) and update your `test.extend` call as shown in the updated usage documentation for v2.x.x.Ensure your project is configured for ESM, and update all imports to use `import` statements. If you strictly require CommonJS, consider using an older version (pre-2.x.x) or transpiling your code.
Always define your extended `test` object in a separate, reusable 'test-base' file (e.g., `tests/fixtures/performance-test.ts`) and import it into your individual test files. This ensures consistent fixture application and better maintainability.
Utilize the `performanceResultsDirectoryName` and `performanceResultsFileName` options within `PerformanceOptions` to specify unique output paths for different test runs or scenarios, preventing data loss.
Ensure you are using `import { test as base } from '@playwright/test';` and that your Playwright dependency is up-to-date and compatible with 'playwright-performance' v2.x.x.Run `npm install playwright-performance --save-dev`. Verify your `tsconfig.json` includes `playwright-performance` in `types` or `typeRoots`, and ensure your environment supports ESM imports correctly, especially for Node.js projects.
Ensure your test file imports and uses the 'test' object that has been extended by `playwright-performance` (e.g., `import { test } from '../path/to/my-extended-test-base';`) and that 'performance' is destructured in your test function signature: `async ({ page, performance }) => { ... }`.