Lesson
Intercept a WebSocket connection with Mock Service Worker
Intercept a WebSocket connection in a Remix app using Mock Service Worker.
- Access
- Included
- Transcript
- Needs source
To intercept any WebSocket connection in your app, create a WebSocket link using the ws.link() API from MSW. Provide it a URL predicate and store the link in a variable. Then, add the connection event listener to your WebSocket link to know when a connection is being established. Provide the result of that event listener to your handlers array, and you're good to go!