Course lesson
Intercept WebSocket Client Events with Mock Service Worker
The connection event listener of your WebSocket link exposes a bunch of useful parameters to you. One of those parameters is the client object that represents the intercepted WebSocket client that establishes the connection.
- Duration
- 2 min
- Access
- Free
- Transcript
- Needs source
The connection event listener of your WebSocket link exposes a bunch of useful parameters to you. One of those parameters is the client object that represents the intercepted WebSocket client that establishes the connection.
Add a message event listener on that client to know when it sends any messages in your application. And yes, this is a regular event listener! This means you get a MessageEvent instance as a parameter, and can observe the data sent via WebSocket.