# Behavior traces — mswjs/msw

> Canonical page: https://codevetter.com/unpack/msw/behavior-traces

# Behavior traces — mswjs/msw

Scanned commit 6d6aef1640ace2ce2bd90252c71bdbc53262efd3 (2026-09-30). Generated by codevetter codevetter 1.15.0 on 2026-10-02.

Source inspection; upstream code and tests were not executed.

The following traces follow concrete startup, response, persistence, isolation, and reload paths through the inspected source. Browser startup waits for worker activation and a client confirmation before returning a registration. HTTP resolution distinguishes explicit bypass, unhandled traffic, fallthrough, and mocked responses. Node boundaries and browser persistence preserve different kinds of state, while Vite serializes network changes around hot updates.
- Browser startup: setupWorker → start → ServiceWorkerSource.from → network.configure → network.enable → source.enable → #startWorker/getWorkerInstance → integrity check → activation wait → MOCK_ACTIVATE/MOCKING_ENABLED → return registration; unsupported Service Worker environments take FallbackHttpSource. — [src/browser/setup-worker.ts#L43-L83](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/browser/setup-worker.ts#L43-L83) [src/browser/sources/service-worker-source.ts#L112-L154](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/browser/sources/service-worker-source.ts#L112-L154) [src/browser/sources/service-worker-source.ts#L212-L223](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/browser/sources/service-worker-source.ts#L212-L223) [src/browser/sources/service-worker-source.ts#L286-L301](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/browser/sources/service-worker-source.ts#L286-L301)
- Browser mock request: worker fetch handler → handleRequest/getResponse → REQUEST → #handleRequest/deserializeRequest → queue → HttpNetworkFrame.resolve/executeHandlers → RequestHandler.run → respondWith/MOCK_RESPONSE → respondWithMock; RESPONSE subsequently drives page lifecycle events. — [src/mockServiceWorker.js#L139-L151](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/mockServiceWorker.js#L139-L151) [src/mockServiceWorker.js#L335-L355](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/mockServiceWorker.js#L335-L355) [src/browser/sources/service-worker-source.ts#L304-L315](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/browser/sources/service-worker-source.ts#L304-L315) [src/browser/sources/service-worker-source.ts#L369-L383](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/browser/sources/service-worker-source.ts#L369-L383)
- Unhandled HTTP flow: resolve emits request:start, checks bypass, calls executeHandlers, then executes onUnhandledFrame when no handler matches; unmatched CONNECT bypasses silently, and matched handlers returning nothing or passthrough bypass without the unhandled path. — [src/core/experimental/frames/http-frame.ts#L149-L168](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/core/experimental/frames/http-frame.ts#L149-L168) [src/core/experimental/frames/http-frame.ts#L193-L236](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/core/experimental/frames/http-frame.ts#L193-L236) [src/core/experimental/frames/http-frame.ts#L248-L271](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/core/experimental/frames/http-frame.ts#L248-L271)
- Node startup/request flow: setupServer creates AsyncHandlersController and defineNetwork → listen configures onUnhandledFrame and enables sources → InterceptorSource.apply/listeners → #handleRequest/queue → frame resolution → controller.respondWith; close initiates network.disable synchronously. — [src/node/setup-server.ts#L40-L47](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/node/setup-server.ts#L40-L47) [src/node/setup-server-common.ts#L21-L40](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/node/setup-server-common.ts#L21-L40) [src/core/experimental/sources/interceptor-source.ts#L53-L82](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/core/experimental/sources/interceptor-source.ts#L53-L82) [src/core/experimental/sources/interceptor-source.ts#L153-L156](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/core/experimental/sources/interceptor-source.ts#L153-L156)
- Scoped override flow: server.boundary returns a wrapper → snapshots current handler buckets → AsyncLocalStorage.run creates a local context → use prepends per-kind overrides → frame lookup reads that context; outside a boundary, #getContext falls back to the server context. — [src/node/async-handlers-controller.ts#L30-L48](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/node/async-handlers-controller.ts#L30-L48) [src/node/async-handlers-controller.ts#L51-L67](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/node/async-handlers-controller.ts#L51-L67) [src/core/experimental/handlers-controller.ts#L144-L160](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/core/experimental/handlers-controller.ts#L144-L160) [src/core/experimental/define-network.ts#L197-L203](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/core/experimental/define-network.ts#L197-L203)
- Cookie persistence flow: storeResponseCookies extracts raw Set-Cookie → CookieStore.setCookie updates tough-cookie → persist serializes jar entries to localStorage; the next browser CookieStore constructor restores entries, and getAllRequestCookies includes them only for eligible credentials. — [src/core/utils/request/store-response-cookies.ts#L4-L14](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/core/utils/request/store-response-cookies.ts#L4-L14) [src/core/utils/cookie-store.ts#L23-L35](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/core/utils/cookie-store.ts#L23-L35) [src/core/utils/cookie-store.ts#L45-L95](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/core/utils/cookie-store.ts#L45-L95) [src/core/utils/request/get-request-cookies.ts#L25-L42](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/core/utils/request/get-request-cookies.ts#L25-L42)
- WebSocket flow: InterceptorSource queues a WebSocket frame → frame selects websocket handlers → handler.run matches and applies extensions → logger attaches → kConnect emits connection → link listener registers the client; broadcastExcept sends through local or remote client handles. — [src/core/experimental/sources/interceptor-source.ts#L122-L129](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/core/experimental/sources/interceptor-source.ts#L122-L129) [src/core/experimental/frames/websocket-frame.ts#L143-L178](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/core/experimental/frames/websocket-frame.ts#L143-L178) [src/ws/websocket-handler.ts#L196-L227](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/ws/websocket-handler.ts#L196-L227) [src/ws/ws.ts#L209-L237](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/ws/ws.ts#L209-L237)
- Vite flow: resolveId maps virtual:msw to runtime → virtual options select browser/server defaults → runtime defines a disabled network → user configure/enable starts mocking; beforeUpdate disables, afterUpdate resumes if previously enabled, and dispose retires the instance and removes HMR listeners. — [src/vite/plugin.ts#L56-L83](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/vite/plugin.ts#L56-L83) [src/vite/runtime.ts#L23-L24](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/vite/runtime.ts#L23-L24) [src/vite/runtime.ts#L55-L80](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/vite/runtime.ts#L55-L80) [src/vite/runtime.ts#L86-L116](https://github.com/mswjs/msw/blob/6d6aef1640ace2ce2bd90252c71bdbc53262efd3/src/vite/runtime.ts#L86-L116)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
