Skip to content

Fix be defensive around use of window websocket#2

Closed
keithamus wants to merge 2 commits intonathanboktae:masterfrom
keithamus:fix-be-defensive-around-use-of-window-websocket
Closed

Fix be defensive around use of window websocket#2
keithamus wants to merge 2 commits intonathanboktae:masterfrom
keithamus:fix-be-defensive-around-use-of-window-websocket

Conversation

@keithamus
Copy link
Copy Markdown

See the discussion up until now at appuri/robust-websocket#24

}
})(function(global, navigator) {

var WebSocket = global.WebSocket
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per appuri/robust-websocket#24 (comment)

The reason for this change is: WebSocket has been overriden by browser extensions and users want to ensure that RobustWebSocket's implementation doesn't change from under them.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WebSocket has been overriden by browser extensions and users want to ensure that RobustWebSocket's implementation doesn't change from under them.

But this can make it worse. Based on the load order (which is determined by what?) RobustWebSocket could close over the extention's implentation, or the native implementation. In the current usage, with lazy invocation, the user's code has more time and control to inject a different implementation.

}
})(function(global, navigator) {

var WebSocket = global.WebSocket
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WebSocket has been overriden by browser extensions and users want to ensure that RobustWebSocket's implementation doesn't change from under them.

But this can make it worse. Based on the load order (which is determined by what?) RobustWebSocket could close over the extention's implentation, or the native implementation. In the current usage, with lazy invocation, the user's code has more time and control to inject a different implementation.


self.open = function() {
if (realWs.readyState !== WebSocket.OPEN && realWs.readyState !== WebSocket.CONNECTING) {
if (realWs.readyState !== self.OPEN && realWs.readyState !== self.CONNECTING) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't and should not need to reimplement logic that is in the underlying WebSocket.prototype.send method. if it's missing, that's another thing and in that case, throwing an Error indicating it's missing is the most explicit, best experience for the user.

@keithamus keithamus closed this Dec 2, 2021
@keithamus keithamus deleted the fix-be-defensive-around-use-of-window-websocket branch December 2, 2021 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants