{"id":45790,"library":"playwright-network-cache","title":"playwright-network-cache","description":"A Playwright test utility for caching network requests on the filesystem to speed up E2E tests. Version 0.3.0 is the latest stable release, with a focus on simplicity and transparency (cached responses stored as clear JSON files, not HAR). It supports automatic caching, TTL-based refresh, runtime response modification, and flexible path splitting. Unlike manual mocking or HAR-based tools, it requires no setup beyond a fixture and works transparently with real API calls. Release cadence is irregular; maintained by vitalets. Ships TypeScript types.","status":"active","version":"0.3.0","language":"javascript","source_language":"en","source_url":"git://github.com/vitalets/playwright-network-cache","tags":["javascript","playwright","network","cache","testing","e2e","typescript"],"install":[{"cmd":"npm install playwright-network-cache","lang":"bash","label":"npm"},{"cmd":"yarn add playwright-network-cache","lang":"bash","label":"yarn"},{"cmd":"pnpm add playwright-network-cache","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency — requires Playwright test runner for fixture integration","package":"playwright","optional":false}],"imports":[{"note":"ESM-only package (type: module). CommonJS require() will fail.","wrong":"const CacheRoute = require('playwright-network-cache')","symbol":"CacheRoute","correct":"import { CacheRoute } from 'playwright-network-cache'"},{"note":"Type import for TypeScript users. You can also inline the options interface.","wrong":"type CacheRouteOptions = import('playwright-network-cache').CacheRouteOptions","symbol":"CacheRouteOptions","correct":"import type { CacheRouteOptions } from 'playwright-network-cache'"},{"note":"Package exports a default class CacheRoute. Named export `CacheRoute` is also available as a workaround.","wrong":"import cacheRoute from 'playwright-network-cache'","symbol":"default import","correct":"import CacheRoute from 'playwright-network-cache'"}],"quickstart":{"code":"import { test as base, expect } from '@playwright/test';\nimport CacheRoute from 'playwright-network-cache';\n\nconst test = base.extend({\n  cacheRoute: async ({ page }, use) => {\n    const cacheRoute = new CacheRoute(page, { ttlMinutes: 10 });\n    await use(cacheRoute);\n  },\n});\n\ntest('api caching', async ({ page, cacheRoute }) => {\n  await cacheRoute.GET('https://api.example.com/users*');\n  await page.goto('https://example.com/users');\n  await expect(page.locator('text=User list')).toBeVisible();\n});","lang":"typescript","description":"Demonstrates setting up a CacheRoute fixture with TTL and using GET to cache an API call."},"warnings":[{"fix":"Update Playwright to >=1.20 or use a compatible version of the library.","message":"Playwright version 1.20+ required for route interception (page.route)","severity":"breaking","affected_versions":"<0.1.0"},{"fix":"Use `baseDir` instead of `baseDirectory` in options.","message":"The `CacheRoute` constructor options `baseDirectory` is deprecated in favor of `baseDir`","severity":"deprecated","affected_versions":"<0.3.0"},{"fix":"Add a cleanup step in your test setup or CI, or set `ttlMinutes` to force refresh periodically.","message":"Cache files are not automatically cleaned; they persist across test runs. You must manually delete the .network-cache directory or rely on TTL","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"For HEAD, OPTIONS, etc., use the generic `route` method.","message":"Only HTTP methods GET, POST, PUT, PATCH, DELETE are supported by shorthand methods. For other methods, use `cacheRoute.route(method, url, options)`","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use the `splitByUrlParams` option to group similar URLs, or implement custom `matchRequest` logic.","message":"The cache is based on the full request URL (including query params). If query params vary unpredictably, cache hit ratio drops; use `splitByUrlParams` or `matchRequest` to normalize","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Set `\"type\": \"module\"` in package.json, or use `import('playwright-network-cache').then(mod => ...)`","message":"The package is ESM-only (type: module). If your project uses CommonJS, you must use dynamic import() or set type: module","severity":"gotcha","affected_versions":">=0.2.0"}],"env_vars":null,"search_vec":"'0.3.0':22 'api':79 'automat':46 'base':50,65 'beyond':71 'cach':4,10,35,47,94 'cadenc':82 'call':80 'clear':39 'e2e':19,96 'file':41 'filesystem':15 'fixtur':73 'flexibl':56 'focus':30 'har':43,64 'har-bas':63 'irregular':84 'javascript':91 'json':40 'latest':25 'maintain':85 'manual':60 'mock':61 'modif':54 'network':3,11,93 'path':57 'playwright':2,6,92 'playwright-network-cach':1 'real':78 'refresh':51 'releas':27,81 'request':12 'requir':68 'respons':36,53 'runtim':52 'setup':70 'ship':88 'simplic':32 'speed':17 'split':58 'stabl':26 'store':37 'support':45 'test':7,20,95 'tool':66 'transpar':34,76 'ttl':49 'ttl-base':48 'type':90 'typescript':89,97 'unlik':59 'util':8 'version':21 'vitalet':87 'work':75","created_at":"2026-06-07T12:56:44.848050+00:00","updated_at":"2026-06-07T12:56:44.848050+00:00","problems":[{"fix":"Use `new CacheRoute(page, opts)` consistently.","cause":"Using `CacheRoute(page, opts)` without `new` (valid JS, but TS strict mode may warn)","error":"TypeError: Class constructor CacheRoute cannot be invoked without 'new'"},{"fix":"Run `npm i -D playwright-network-cache` and verify package.json has it as devDependency.","cause":"Package not installed, or import path typo","error":"Cannot find module 'playwright-network-cache'"},{"fix":"Ensure each pattern is only cached once per test, or use `cacheRoute.ALL` with `matchRequest` to handle multiple patterns.","cause":"Calling cacheRoute.GET/POST/etc. twice on the same URL pattern without calling `page.unroute` first","error":"Error: page.route: Route is already handled"},{"fix":"Use `import CacheRoute from 'playwright-network-cache'` and instantiate with `new`.","cause":"Importing wrong symbol or using default import incorrectly in TypeScript","error":"TypeError: cacheRoute.GET is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/vitalets/playwright-network-cache#readme","github":"git://github.com/vitalets/playwright-network-cache","docs":null,"changelog":null,"pypi":null,"npm":"playwright-network-cache","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}