Skip to content

Commit b903dd6

Browse files
committed
linuxsessionmgr: special case VSCode remote session
In a Visual Studio Code remote session, we may be able to launch a browser without the `DISPLAY` environment variable set. This is because VSCode sets the `BROWSER` environment variable in remote sessions, such that it can forward requests to start a browser to the client machine. However! There are several types of remote session in VSCode, and the way they handle automatic port forwarding differs slightly. Since a very common case in GCM for launching the user browser is the ability to connect back to GCM via localhost:<port>, we only consider a subset of remote sessions to be able to launch a browser: * Remote SSH [YES] * Dev Containers [YES] * Remote Tunnel [NO] Sadly, for whatever reason, the remote connection over Microsoft Dev Tunnels does NOT automatically surface a forwarded port to localhost on the client. The forwarded port is only available via the devtunnels.ms URLs. Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
1 parent 04b949a commit b903dd6

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

src/shared/Core/Interop/Linux/LinuxSessionManager.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,46 @@ private bool GetWebBrowserAvailable()
9595
return true;
9696
}
9797

98+
//
99+
// We may also be able to launch a browser if we're inside a Visual Studio Code remote session.
100+
// VSCode overrides the BROWSER environment variable to a script that allows the user to open
101+
// the browser on their client machine.
102+
//
103+
// Even though we can start a browser, one piece of critical functionality we need is the ability
104+
// to have that browser be able to connect back to GCM over localhost. There are several types
105+
// of VSCode remote session, and only some of them automatically forward ports in such a way that
106+
// the client browser can automatically connect back to GCM over localhost.
107+
//
108+
// * Remote SSH [OK]
109+
// Connection over SSH to a remote machine.
110+
//
111+
// * Dev Containers [OK]
112+
// Connection to a container.
113+
//
114+
// * Remote Tunnels [Not OK - forwarded ports not accessible on the client via localhost]
115+
// Connection to a remote machine over the Internet using Microsoft Dev Tunnels.
116+
//
117+
// * WSL [Ignored - already handled above]
118+
//
119+
if (Environment.Variables.ContainsKey("VSCODE_IPC_HOOK_CLI") &&
120+
Environment.Variables.ContainsKey("BROWSER"))
121+
{
122+
if (Environment.Variables.ContainsKey("SSH_CONNECTION"))
123+
{
124+
Trace.WriteLine("VSCode (SSH) detected - browser is available.");
125+
return true;
126+
}
127+
128+
if (Environment.Variables.ContainsKey("REMOTE_CONTAINERS"))
129+
{
130+
Trace.WriteLine("VSCode (Dev Containers) detected - browser is available.");
131+
return true;
132+
}
133+
134+
Trace.WriteLine("VSCode (Tunnel) detected - browser is not available.");
135+
return false;
136+
}
137+
98138
// We need a desktop session to be able to launch the browser in the general case
99139
return IsDesktopSession;
100140
}

0 commit comments

Comments
 (0)