12

I've created a simple WebSocket server and am trying to connect to it with the following code:

function test(name) {
    var ws = new WebSocket('ws://localhost:1234');
    ws.onopen = function () {
        ws.send('Hello from ' + name);
    }
}
test('Edge');

This works fine from Chrome and IE11 on Windows10 but when I try from Edge, the onopen function isn't called, instead I eventually get the following error:

SCRIPT12029: WebSocket Error: Network Error 12029, A connection with the server could not be established

This is happening for version 12.10240 of Edge.

A similar problem was asked about here but the error message is different.

Things I tried:

  • IP - localhost, 127.0.0.1, the actual IP
  • Allow localhost loopback flag - both on and off

When trying to communicate with a different machine the problem does not occur.

Is this a defect in Edge or am I doing something wrong?

Community
  • 1
  • 1
Motti
  • 110,860
  • 49
  • 189
  • 262
  • Report bug to Microsoft maybe? – Jan Aug 02 '15 at 16:25
  • @Jan I sent feedback but in parallel I want to make sure I'm not missing something obvious (I don't have much experience with WebSockets) – Motti Aug 02 '15 at 16:53
  • 1
    Maybe, but this sure sounds like a bug to me. – Jan Aug 02 '15 at 17:26
  • This is not a bug. This all has to do with `loopback`. When you connect to a different IP (one that is not `localhost`, `::1` or `127.0.0.1`) the IP is generally not considered a `loopback` attempt, hence the need for `CheckNetIsolation`, which is specific to `ModernUI` applications (Edge is a ModernUI application). This is only one of many gotcha's with IE11 and Edge when it comes to loopback connections. On a domain network, the connection can still be blocked after calling `CheckNetIsolation` due to the changing of the definition `Local Intranet Zone` on a domain. – tresf Aug 16 '16 at 02:54

1 Answers1

14

I had a similar problem, but it was when actually navigating to pages in the browser. I could use the phrase localhost and it worked fine, but I didn't work when I used my machine's name. I found this forum where they suggested that you run the following command in a administrator prompt:

CheckNetIsolation LoopbackExempt -a -n=Microsoft.MicrosoftEdge_8wekyb3d8bbwe

Worked for me. Thought you might be seeing some form of the same issue.

As the forum suggests, you can now also do this by opening Edge and navigating to "about:flags", then tick "Allow localhost loopback (this might put your device at risk)" under "Developer Settings". Should feel a little safer than pasting random stuff into your command prompt.

Edit: As tresf pointed out below, the loopback checkbox in the about:flags appears to have stopped working (as a fix), so you'll have use the CheckNetIsolation command, to make Edge exempt.

Jools
  • 839
  • 8
  • 22
  • 4
    In recent versions of Edge, the loopback flag seems to be enabled by default now however the`CheckNetIsolation` fix seems to be required regardless. – tresf Apr 15 '16 at 02:47
  • @QZSupport I had the similar problem and 'CheckNetIsolation' fixed it for me. What does it do? – Sanich Aug 08 '16 at 17:41
  • 2
    @Sanich the explanation from MS is "Edge runs as a Windows modern app different from IE and thus it is has network isolation by default for security reasons.". Note also, "Automatically detect settings" in Local Intranet Zone can have a similar effect in IE if on a domain. https://blogs.msdn.microsoft.com/msgulfcommunity/2015/07/01/how-to-debug-localhost-on-microsoft-edge/ – tresf Aug 10 '16 at 02:32
  • @QZSupport Thanks! What might be the reason that enabling the loopback flag alone doesn't solve the problem and ''CheckNetIsolation" does? – Sanich Aug 10 '16 at 08:00
  • 1
    @Sanich, your question is better directed at the Edge developers, but the Microsoft blog article explains the loopback restriction to be imposed on all ModernUI apps (not just edge), thus making the Edge check box rather redundant. Furthermore, domain environments treat "Local Intranet Zone" different from workstation computers, so resolving/troubleshooting WebSocket to localhost on Edge and IE is an obscure and rather undocumented process. – tresf Aug 11 '16 at 15:20