MCPcopy Index your code
hub / github.com/coder/coder / openMaybePortForwardedURL

Function openMaybePortForwardedURL

site/src/utils/portForward.ts:95–123  ·  view source on GitHub ↗
(
	uri: string,
	proxyHost?: string,
	agentName?: string,
	workspaceName?: string,
	username?: string,
)

Source from the content-addressed store, hash-verified

93// openMaybePortForwardedURL tries to open the provided URI through the
94// port-forwarded URL if it is localhost, otherwise opens it normally.
95export const openMaybePortForwardedURL = (
96 uri: string,
97 proxyHost?: string,
98 agentName?: string,
99 workspaceName?: string,
100 username?: string,
101) => {
102 const open = (uri: string) => {
103 // Copied from: https://github.com/xtermjs/xterm.js/blob/master/addons/xterm-addon-web-links/src/WebLinksAddon.ts#L23
104 const newWindow = window.open();
105 if (newWindow) {
106 try {
107 newWindow.opener = null;
108 } catch {
109 // no-op, Electron can throw
110 }
111 newWindow.location.href = uri;
112 } else {
113 console.warn("Opening link blocked as opener could not be cleared");
114 }
115 };
116
117 if (!agentName || !workspaceName || !username || !proxyHost) {
118 open(uri);
119 return;
120 }
121
122 open(rewriteLocalhostURL(uri, proxyHost, agentName, workspaceName, username));
123};
124
125export const saveWorkspaceListeningPortsProtocol = (
126 workspaceID: string,

Callers 2

TerminalPageFunction · 0.90
handleOpenLinkFunction · 0.90

Calls 2

rewriteLocalhostURLFunction · 0.85
openFunction · 0.70

Tested by

no test coverage detected