Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 345e56c

Browse files
tlancinavicb
authored andcommitted
fix(WebSocket): don't patch EventTarget methods twice
closes #235 On older versions of Chrome, patching via property descriptors isn't available, but unlike Safari, window.EventTarget exists and is already patched, so the EventTarget methods on WebSocket.prototype don't need to be patched again. Closes #233.
1 parent 767a30e commit 345e56c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/patch/websocket.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import * as utils from '../utils';
33
// we have to patch the instance since the proto is non-configurable
44
export function apply() {
55
var WS = (<any>global).WebSocket;
6-
utils.patchEventTargetMethods(WS.prototype);
6+
// On Safari window.EventTarget doesn't exist so need to patch WS add/removeEventListener
7+
// On older Chrome, no need since EventTarget was already patched
8+
if (!(<any>global).EventTarget) {
9+
utils.patchEventTargetMethods(WS.prototype);
10+
}
711
(<any>global).WebSocket = function(a, b) {
812
var socket = arguments.length > 1 ? new WS(a, b) : new WS(a);
913
var proxySocket;

0 commit comments

Comments
 (0)