Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IE11 SyntaxError #117

Open
stellusUi opened this issue Apr 25, 2017 · 2 comments
Open

IE11 SyntaxError #117

stellusUi opened this issue Apr 25, 2017 · 2 comments

Comments

@stellusUi
Copy link

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 [email protected] 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.

Thanks in advance
ie-angular-websockets

@stellusUi
Copy link
Author

stellusUi commented Apr 28, 2017

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;

@jpmasters
Copy link

@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;

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

No branches or pull requests

2 participants