IE11 SyntaxError
stellusUi opened this issue · 2 comments
I seem to keep getting a SyntaxError in IE11 when using the minified version of this package (2.0.0).
It also happens when I minify it as part of my full library set as well.
The problem seems to be the comma before the this.createWebSocketBackend
throw new Error("Invalid url provided");return t?new a(e,t):new a(e)},this.createWebSocketBackend
The original source version doesn't seem to warrant a new comma from what I can tell (~Line 388)
function $WebSocketBackendProvider($log) {
this.create = function create(url, protocols) {
var match = /wss?:\/\//.exec(url);
if (!match) {
throw new Error('Invalid url provided');
}
if (protocols) {
return new Socket(url, protocols);
}
return new Socket(url);
};
this.createWebSocketBackend = function createWebSocketBackend(url, protocols) {
$log.warn('Deprecated: Please use .create(url, protocols)');
return this.create(url, protocols);
};
}
I'm using grunt-contrib-uglify@2.3.0 and can't seem to find a way to remove the comma using any of the UglifyJS2 compressor options.
https://github.com/mishoo/UglifyJS2#compressor-options
Thoughts welcomed.
It turns out the syntaxError is specifically to that return new Socket(url);
line. Even using the unminimized version of the file still produces the error in IE11 Win7.
I ended up wrapping it with a try/catch for now just so I can use it with other browsers without the IE11 error
try {
return new Socket(url);
} catch (exception) {
if (window.console) {
// no-op on the syntax error
//console.log(exception);
}
}
// need to return false vs null (due to future IE error of referencing null within the library)
return false;
@stellusUi - Are you by any chance creating an anchor to build the URL? If so I ran into the same problem and it was because IE11 strips the leading / from pathname and when the URL was reassembled, it was badly formed. I solved it by checking for a leading / in pathname and inserting one if it wasn't there e.g.:
// IE11 strips the leading "/" from the path
var pnSep = uri.pathname.indexOf("/") === 0 ? "" : "/";
var socketURL = protocol + '//' + uri.hostname + ':' + uri.port + pnSep + uri.pathname + '/websocket' + "?authenticationToken=" + authenticationToken + "&sessionId=" + sessionId;