joewalnes / reconnecting-websocket

A small decorator for the JavaScript WebSocket API that automatically reconnects
MIT License
4.21k stars 970 forks source link

Strict mode violation in Chrome (with fix) #126

Open asdf072 opened 6 months ago

asdf072 commented 6 months ago

I recently started getting an error in Chrome. [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.

I tracked it down to the timeout function in the this.open method. The function in the setTimeout makes a direct call to websocket.close(). Line #227.

Using func.call() to help it define this seems to have cleared up the error. Can anyone see any unintended issues?

            var localWs = ws;
            var timeout = setTimeout(function() {
                if (self.debug || ReconnectingWebSocket.debugAll) {
                    console.debug('ReconnectingWebSocket', 'connection-timeout', self.url);
                }
                timedOut = true;
                //localWs.close(); // this causes a strict mode violation
                localWs.close.call(localWs); // better
                timedOut = false;
            }, self.timeoutInterval);
asdf072 commented 6 months ago

But now, minifying breaks it ... Hm

Tangee69 commented 5 months ago
bj00rn commented 5 months ago

@asdf072 try the fork project at https://github.com/partykit/partykit/tree/main/packages/partysocket and file an issue there if problem still