mswjs / interceptors

Low-level network interception library.
https://npm.im/@mswjs/interceptors
MIT License
565 stars 127 forks source link

TypeError: Cannot redefine property: Symbol(kBoundListener) #652

Closed kettanaito closed 1 month ago

kettanaito commented 1 month ago

The following error is thrown when reusing the same function as an event listener for WebSocket:

TypeError: Cannot redefine property: Symbol(kBoundListener)
client.addEventListener('message', clientMessageListener)
client.addEventListener('message', clientMessageListener)

It is thrown because the kBoundListener symbol is trying to be redefined for another listener being attached:

https://github.com/mswjs/interceptors/blob/4fab617266b94e1c84235e355bad1e86687c1850/src/interceptors/WebSocket/WebSocketClientConnection.ts#L91-L96

Instead, we should check if kBoundListener is defined, and if it is, ignore that definition. That means you are reusing the same listener.

kettanaito commented 1 month ago

Released: v0.36.2 🎉

This has been released in v0.36.2!

Make sure to always update to the latest version (npm i @mswjs/interceptors@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.