{"id":33376354,"url":"https://github.com/paperstrike/vitest-playwright-bridge","last_synced_at":"2026-05-11T10:35:25.871Z","repository":{"id":325683011,"uuid":"1102090463","full_name":"PaperStrike/vitest-playwright-bridge","owner":"PaperStrike","description":"Bridge to interact with Playwright directly from Vitest browser tests, enabling advanced browser control and access to Playwright features.","archived":false,"fork":false,"pushed_at":"2025-11-22T19:55:48.000Z","size":0,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-22T20:01:15.699Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/PaperStrike.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2025-11-22T19:55:42.000Z","updated_at":"2025-11-22T19:56:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"b3ee6130-a473-4e1f-9bb6-27ba4252dbb8","html_url":"https://github.com/PaperStrike/vitest-playwright-bridge","commit_stats":null,"previous_names":["paperstrike/vitest-playwright-bridge"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/PaperStrike/vitest-playwright-bridge","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PaperStrike%2Fvitest-playwright-bridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PaperStrike%2Fvitest-playwright-bridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PaperStrike%2Fvitest-playwright-bridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PaperStrike%2Fvitest-playwright-bridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PaperStrike","download_url":"https://codeload.github.com/PaperStrike/vitest-playwright-bridge/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PaperStrike%2Fvitest-playwright-bridge/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":285879574,"owners_count":27247109,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-22T02:00:05.934Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2025-11-23T00:01:43.675Z","updated_at":"2025-11-23T00:02:42.639Z","avatar_url":"https://github.com/PaperStrike.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vitest-playwright-bridge\n[![npm Package](https://img.shields.io/npm/v/vitest-playwright-bridge?logo=npm \"vitest-playwright-bridge\")](https://www.npmjs.com/package/vitest-playwright-bridge)\n\nBridge to interact with Playwright directly from Vitest browser tests, enabling advanced browser control and access to Playwright features. It provides utilities like `pageHandle`, which allow direct interaction with the Playwright [`Page`](https://playwright.dev/docs/api/class-page) object.\n\n## Example\n\n`test/media.test.ts` for [CSS media emulation](https://playwright.dev/docs/api/class-page#page-emulate-media):\n```ts\nimport { describe, test, expect } from 'vitest'\nimport { pageHandle } from 'vitest-playwright-bridge/browser'\n\ndescribe('CSS media emulation', () =\u003e {\n  test.afterEach(async () =\u003e {\n    await pageHandle.evaluate(async (page) =\u003e {\n      await page.emulateMedia({\n        colorScheme: null,\n        contrast: null,\n        forcedColors: null,\n        media: null,\n        reducedMotion: null,\n      })\n    })\n  })\n\n  test('should set dark mode', async () =\u003e {\n    expect(window.matchMedia('(prefers-color-scheme: dark)').matches).toBe(false)\n\n    await pageHandle.evaluate(async (page) =\u003e {\n      await page.emulateMedia({ colorScheme: 'dark' })\n    })\n\n    expect(window.matchMedia('(prefers-color-scheme: dark)').matches).toBe(true)\n  })\n})\n```\n\n## Configuration\n\n`vitest.config.ts` example:\n```ts\nimport { defineConfig } from 'vitest/config'\nimport { playwright } from '@vitest/browser-playwright'\nimport { playwrightBridge } from 'vitest-playwright-bridge/plugin'\n\nexport default defineConfig({\n  plugins: [playwrightBridge()],\n  test: {\n    browser: {\n      provider: playwright(),\n      enabled: true,\n      instances: [\n        { browser: 'chromium' },\n      ],\n    },\n  },\n})\n```\n\n## API\n\n```ts\nimport { pageHandle, contextHandle, route, unroute, unrouteAll, bypassFetch } from 'vitest-playwright-bridge/browser'\n```\n\n### HostHandle\n`HostHandle` is similar to [`JSHandle`](https://playwright.dev/docs/api/class-jshandle) in Playwright.\n\nJust like we pass functions from Node to browsers via `JSHandle.evaluate` in Playwright, we can pass functions from browsers to Node via `HostHandle.evaluate` in this bridge.\n\nThe bridge provides two initial `HostHandle` instances:\n- `pageHandle`: represents the current Playwright [`Page`](https://playwright.dev/docs/api/class-page) object.\n- `contextHandle`: represents the current Playwright [`BrowserContext`](https://playwright.dev/docs/api/class-browsercontext) object.\n\n### Network Routing\nTo support fast, flexible network request matching and routing, the bridge provides direct browser equivalents for Playwright's [`Page.route`](https://playwright.dev/docs/api/class-page#page-route).\n- `route(url, handler)`: adds a route to match network requests.\n- `unroute(url, handler?)`: removes a specific route or all routes matching the URL.\n- `unrouteAll()`: removes all routes.\n\n```ts\nimport { describe, test, expect } from 'vitest'\nimport { route, unrouteAll } from 'vitest-playwright-bridge/browser'\n\ndescribe('network request routing', () =\u003e {\n  test.afterEach(async () =\u003e {\n    await unrouteAll({ behavior: 'wait' })\n  })\n\n  test('should reply with Hello World', async () =\u003e {\n    await route('/hello', async (route) =\u003e {\n      await route.fulfill({ body: 'Hello World' })\n    })\n\n    const response = await fetch('/hello')\n    const text = await response.text()\n    expect(text).toBe('Hello World')\n  })\n})\n```\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaperstrike%2Fvitest-playwright-bridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaperstrike%2Fvitest-playwright-bridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaperstrike%2Fvitest-playwright-bridge/lists"}