joewalnes / reconnecting-websocket

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

Strict mode violation in Chrome (with fix) #126

Open asdf072 opened 10 months ago

asdf072 commented 10 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 10 months ago

But now, minifying breaks it ... Hm

Tangee69 commented 9 months ago
bj00rn commented 8 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