{"id":28718676,"url":"https://github.com/mswjs/playwright","last_synced_at":"2026-02-16T15:06:59.940Z","repository":{"id":297462030,"uuid":"996831339","full_name":"mswjs/playwright","owner":"mswjs","description":"Mock Service Worker binding for Playwright.","archived":false,"fork":false,"pushed_at":"2026-02-14T20:02:12.000Z","size":138,"stargazers_count":249,"open_issues_count":1,"forks_count":12,"subscribers_count":3,"default_branch":"main","last_synced_at":"2026-02-15T18:56:26.717Z","etag":null,"topics":["api","e2e","mock","msw","network","playwright","request","response","test"],"latest_commit_sha":null,"homepage":"https://npmjs.com/@msw/playwright","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mswjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"mswjs","open_collective":"mswjs"}},"created_at":"2025-06-05T14:26:08.000Z","updated_at":"2026-02-14T20:02:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"8ad8aafb-709c-4d7a-9ce7-4d57e339c590","html_url":"https://github.com/mswjs/playwright","commit_stats":null,"previous_names":["mswjs/playwright"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/mswjs/playwright","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mswjs%2Fplaywright","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mswjs%2Fplaywright/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mswjs%2Fplaywright/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mswjs%2Fplaywright/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mswjs","download_url":"https://codeload.github.com/mswjs/playwright/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mswjs%2Fplaywright/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29509246,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-16T09:05:14.864Z","status":"ssl_error","status_checked_at":"2026-02-16T08:55:59.364Z","response_time":115,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","e2e","mock","msw","network","playwright","request","response","test"],"created_at":"2025-06-15T05:03:14.404Z","updated_at":"2026-02-16T15:06:59.935Z","avatar_url":"https://github.com/mswjs.png","language":"TypeScript","readme":"# `@msw/playwright`\n\n[Mock Service Worker](https://mswjs.io) binding for [Playwright](https://playwright.dev/).\n\n## Motivation\n\nWhile you can use MSW in Playwright following the default [Browser integration](https://mswjs.io/docs/integrations/browser), the cross-process messaging in Playwright makes it clunky to work with the `worker` instance in one process (your tests; Node.js) to affect another (your app; browser).\n\n```ts\nawait page.evaluate(() =\u003e {\n  // In order to reference the worker instance in your tests,\n  // you have to set it on `window` alongside any other\n  // functions from the `msw` package you want to use since\n  // you cannot reference them in `page.evaluate` directly.\n  const { worker, http, graphql } = window.msw\n  worker.use(...overrides)\n})\n```\n\nThis package aims to provide a better developer experience when mocking APIs in Playwright.\n\n\u003e Until we ship [cross-process request interception](https://github.com/mswjs/msw/pull/1617), `@msw/playwright` will rely on the `page.route()` API to provision the request interception in your tests. That means you _don't have to initialize the worker script_ to use this package. That also means that any `page.route()` limitations now affect this library. Treat this as an implementation detail that is likely to change in the future.\n\n## Usage\n\n```sh\nnpm i msw @msw/playwright\n```\n\n```ts\n// playwright.setup.ts\nimport { test as testBase } from '@playwright/test'\nimport { type AnyHandler } from 'msw'\nimport { defineNetworkFixture, type NetworkFixture } from '@msw/playwright'\nimport { handlers } from '../mocks/handlers.js'\n\ninterface Fixtures {\n  handlers: Array\u003cAnyHandler\u003e\n  network: NetworkFixture\n}\n\nconst test = testBase.extend\u003cFixtures\u003e({\n  // Initial list of the network handlers.\n  handlers: [handlers, { option: true }],\n\n  // A fixture you use to control the network in your tests.\n  network: [\n    async ({ context, handlers }, use) =\u003e {\n      const network = defineNetworkFixture({\n        context,\n        handlers,\n      })\n\n      await network.enable()\n      await use(network)\n      await network.disable()\n    },\n    { auto: true },\n  ],\n})\n```\n\n```ts\nimport { http, HttpResponse } from 'msw'\nimport { test } from './playwright.setup.js'\n\ntest('displays the user dashboard', async ({ network, page }) =\u003e {\n  // Access the network fixture and use it as the `setupWorker()` API.\n  // No more disrupted context between processes.\n  network.use(\n    http.get('/user', () =\u003e {\n      return HttpResponse.json({\n        id: 'abc-123',\n        firstName: 'John',\n        lastName: 'Maverick',\n      })\n    }),\n  )\n\n  await page.goto('/dashboard')\n})\n```\n\n## Limitations\n\n- Since `context.routeWebSocket()` provides no means of knowing which page triggered a WebSocket connection, relative WebSocket URLs in `ws.link(url)` will be resolved against the _latest_ created page in the browser context.\n\n## Comparison\n\n### `playwright-msw`\n\n[`playwright-msw`](https://github.com/valendres/playwright-msw) is a community package that, just like `@msw/playwright`, aims to provide a better experience when mocking APIs in your Playwright tests.\n\n\u003e While `playwright-msw` is a fantastic tool and a huge inspiration for this package to exist, I believe it approaches the idea at a rather complex angle. That introduces a layer of abstraction that is subjected to the \"left behind\" problem as it needs to map to any MSW changes explicitly.\n\n|                | `playwright-msw`                                                                      | `@msw/playwright`                                                                                  |\n| -------------- | ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |\n| Initialization | `createWorkerFixture()` is used as a _part_ of your custom fixture.                   | `createNetworkFixture()` creates _the entire_ fixture for you, pre-configured.                     |\n| Implementation | Uses a custom router to match handlers and a custom wrapper around `SetupWorker` API. | Uses MSW directly. Uses `page.route()` as the source of the network to route through the handlers. |\n| Feature set    | Supports `http` and `graphql` namespaces.                                             | Supports all namespaces (`http`, `graphql`, `ws`, any other APIs exposed by MSW in the future).    |\n","funding_links":["https://github.com/sponsors/mswjs","https://opencollective.com/mswjs"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmswjs%2Fplaywright","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmswjs%2Fplaywright","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmswjs%2Fplaywright/lists"}