···11+# Browser Tests
22+33+## Using docker playwright
44+55+Some test suites don't support running it remotely (`fixtures/inspect` and `fixtures/insecure-context`).
66+77+```sh
88+# Start playwright browser server
99+pnpm docker up -d
1010+1111+# Run tests with BROWSER_WS_ENDPOINT
1212+BROWSER_WS_ENDPOINT=ws://127.0.0.1:6677/ pnpm test:playwright
1313+```
···71717272These options are directly passed down to `playwright[browser].connect` command. You can read more about the command and available arguments in the [Playwright documentation](https://playwright.dev/docs/api/class-browsertype#browser-type-connect).
73737474+Use `connectOptions.wsEndpoint` to connect to an existing Playwright server instead of launching browsers locally. This is useful for running browsers in Docker, in CI, or on a remote machine.
7575+7476::: warning
7577Since this command connects to an existing Playwright server, any `launch` options will be ignored.
7878+:::
7979+8080+::: details Example: Running a Playwright Server in Docker
8181+To run browsers in a Docker container (see [Playwright Docker guide](https://playwright.dev/docs/docker#remote-connection)):
8282+8383+Start a Playwright server using Docker Compose:
8484+8585+```yaml [docker-compose.yml]
8686+services:
8787+ playwright:
8888+ image: mcr.microsoft.com/playwright:v1.58.1-noble
8989+ command: /bin/sh -c "npx -y playwright@1.58.1 run-server --port 6677 --host 0.0.0.0"
9090+ init: true
9191+ ipc: host
9292+ user: pwuser
9393+ ports:
9494+ - '6677:6677'
9595+```
9696+9797+```sh
9898+docker compose up -d
9999+```
100100+101101+Then configure Vitest to connect to it. The [`exposeNetwork`](https://playwright.dev/docs/api/class-browsertype#browser-type-connect-option-expose-network) option lets the containerized browser reach Vitest's dev server on the host:
102102+103103+```ts [vitest.config.ts]
104104+import { playwright } from '@vitest/browser-playwright'
105105+import { defineConfig } from 'vitest/config'
106106+107107+export default defineConfig({
108108+ test: {
109109+ browser: {
110110+ provider: playwright({
111111+ connectOptions: {
112112+ wsEndpoint: 'ws://127.0.0.1:6677/',
113113+ exposeNetwork: '<loopback>',
114114+ },
115115+ }),
116116+ instances: [
117117+ { browser: 'chromium' },
118118+ { browser: 'firefox' },
119119+ { browser: 'webkit' },
120120+ ],
121121+ },
122122+ },
123123+})
124124+```
76125:::
7712678127## contextOptions
+4-7
test/browser/specs/utils.ts
···22import type { TestUserConfig } from 'vitest/node'
33import type { RunVitestConfig, TestFsStructure, VitestRunnerCLIOptions } from '../../test-utils'
44import { runInlineTests, runVitest } from '../../test-utils'
55-import { browser, instances, provider } from '../settings'
55+import { instances, provider } from '../settings'
6677-export { browser, instances, provider } from '../settings'
77+export { instances, provider } from '../settings'
8899export async function runInlineBrowserTests(
1010 structure: TestFsStructure,
···2121 enabled: true,
2222 provider,
2323 instances,
2424- headless: browser !== 'safari',
2424+ headless: true,
2525 ...config?.browser,
2626 } as TestUserConfig['browser'],
2727 },
···3939 watch: false,
4040 reporters: 'none',
4141 ...config,
4242- browser: {
4343- headless: browser !== 'safari',
4444- ...config?.browser,
4545- } as TestUserConfig['browser'],
4242+ browser: { headless: true, ...config?.browser },
4643 $viteConfig: viteOverrides,
4744 }, include, runnerOptions)
4845}