Skip to content

Commit

Permalink
Support path-only WebSocket URLs in hosted mode (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
motiz88 authored Feb 23, 2024
1 parent 3b3ac6c commit 9ceb0ad
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion front_end/core/sdk/Connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,15 @@ function createMainConnection(websocketConnectionLost: () => void): ProtocolClie
const wsParam = Root.Runtime.Runtime.queryParam('ws');
const wssParam = Root.Runtime.Runtime.queryParam('wss');
if (wsParam || wssParam) {
const ws = (wsParam ? `ws://${wsParam}` : `wss://${wssParam}`) as Platform.DevToolsPath.UrlString;
const scheme = wsParam ? 'ws' : 'wss';
// ws[s]Param is either:
// 1. The hierarchical part of a URL (with the scheme and :// removed).
// 2. A path-absolute URL (beginning with `/`) relative to the current host. This is only meaningful in hosted mode.
let schemelessUrl = (wsParam ? wsParam : wssParam) as string;
if (Host.InspectorFrontendHost.InspectorFrontendHostInstance.isHostedMode() && schemelessUrl.startsWith('/')) {
schemelessUrl = `${window.location.host}${schemelessUrl}`;
}
const ws = `${scheme}://${schemelessUrl}` as Platform.DevToolsPath.UrlString;
return new WebSocketConnection(ws, websocketConnectionLost);
}
if (Host.InspectorFrontendHost.InspectorFrontendHostInstance.isHostedMode()) {
Expand Down

0 comments on commit 9ceb0ad

Please sign in to comment.