Skip to content

MSW intercepts plain WebSocket but fails to intercept Socket.IO connections #12

Closed
@ccpu

Description

@ccpu

I'm encountering a problem in my local development environment when using MSW with Socket.IO. For some strange reason, MSW is able to intercept a plain WebSocket connection when I use:

new WebSocket("ws://localhost:3000/socket.io/?EIO=4&transport=websocket");

However, it fails to intercept when I use the Socket.IO client:

const socket = io("ws://localhost:3000", {
  retries: 1,
  transports: ["websocket"],
  port: 3000,
});
socket.connect();

Note that Socket.IO client automatically appends /socket.io/ to the URL, so both are attempting to connect to the same endpoint.

I have created a minimal reproduction:

The GitHub repo might be more reliable for reproduction.

Any idea what I might be doing wrong or what modifications are needed to allow MSW to intercept Socket.IO connections as it does with a plain WebSocket?

Thanks in advance for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions