# Playwright Egress Guard Design

## Purpose

The local Playwright check must not contact a non-loopback host.
The guard must cover the initial page, popups, other pages, WebSockets, and service workers.
The public-site check must keep its current behavior.

## Design

Install the HTTP and WebSocket routes on the local test `BrowserContext`.
Install both routes before the first navigation.
Use the shared URL policy to allow only `localhost`, `127.0.0.1`, and `::1`.
Abort each forbidden HTTP request.
Close each forbidden WebSocket without a server connection.
Record each forbidden URL for the test failure message.

Set `serviceWorkers` to `block` in the shared Playwright configuration.
This setting prevents a service worker from bypassing request routing.

## Tests

Use local receivers as safe substitutes for forbidden endpoints.
Access each receiver through `0.0.0.0`.
Verify that image requests, popup navigation, and WebSocket connections do not reach the receivers.
Verify that service-worker registration does not request its script.
Report each unexpected receiver request in the test failure.

Run the offline suite and the focused routing suite.
Run the local site check against the isolated WordPress stack when Docker is available.
Do not run the production site check.

## Documentation

Add `npm ci` and `npx playwright install chromium` to the local setup sequence.
Place both commands before `npm test`.
