diff --git a/packages/playwright-core/src/server/trace/viewer/traceViewer.ts b/packages/playwright-core/src/server/trace/viewer/traceViewer.ts index b1cc8141a4..b8dc3e5314 100644 --- a/packages/playwright-core/src/server/trace/viewer/traceViewer.ts +++ b/packages/playwright-core/src/server/trace/viewer/traceViewer.ts @@ -125,8 +125,6 @@ export async function installRootRedirect(server: HttpServer, traceUrls: string[ for (const reporter of options.reporter || []) params.append('reporter', reporter); - params.set('server', server.urlPrefix('precise')); - const urlPath = `./trace/${options.webApp || 'index.html'}?${params.toString()}`; server.routePath('/', (_, response) => { response.statusCode = 302; diff --git a/packages/trace-viewer/src/sw/main.ts b/packages/trace-viewer/src/sw/main.ts index d977b0d7b7..4d01ef2a61 100644 --- a/packages/trace-viewer/src/sw/main.ts +++ b/packages/trace-viewer/src/sw/main.ts @@ -43,12 +43,9 @@ async function loadTrace(traceUrl: string, traceFileName: string | null, client: const clientId = client?.id ?? ''; let data = clientIdToTraceUrls.get(clientId); if (!data) { - let traceViewerServerBaseUrl = self.registration.scope; - if (client?.url) { - const clientUrl = new URL(client.url); - if (clientUrl.searchParams.has('server')) - traceViewerServerBaseUrl = clientUrl.searchParams.get('server')!; - } + let traceViewerServerBaseUrl = new URL('../', client?.url ?? self.registration.scope); + if (traceViewerServerBaseUrl.searchParams.has('server')) + traceViewerServerBaseUrl = new URL(traceViewerServerBaseUrl.searchParams.get('server')!, traceViewerServerBaseUrl); data = { limit, traceUrls: new Set(), traceViewerServer: new TraceViewerServer(traceViewerServerBaseUrl) }; clientIdToTraceUrls.set(clientId, data); diff --git a/packages/trace-viewer/src/sw/traceModelBackends.ts b/packages/trace-viewer/src/sw/traceModelBackends.ts index ec367575e3..95efffd502 100644 --- a/packages/trace-viewer/src/sw/traceModelBackends.ts +++ b/packages/trace-viewer/src/sw/traceModelBackends.ts @@ -146,7 +146,7 @@ function formatUrl(trace: string, server: TraceViewerServer) { } export class TraceViewerServer { - constructor(private readonly baseUrl: string) {} + constructor(private readonly baseUrl: URL) {} getFileURL(path: string): URL { const url = new URL('trace/file', this.baseUrl); diff --git a/packages/trace-viewer/src/ui/uiModeView.tsx b/packages/trace-viewer/src/ui/uiModeView.tsx index 23138b7f0b..be0dd8f55f 100644 --- a/packages/trace-viewer/src/ui/uiModeView.tsx +++ b/packages/trace-viewer/src/ui/uiModeView.tsx @@ -47,9 +47,11 @@ const xtermDataSource: XtermDataSource = { }; const searchParams = new URLSearchParams(window.location.search); -const guid = searchParams.get('ws'); -const wsURL = new URL(`../${guid}`, window.location.toString()); -wsURL.protocol = (window.location.protocol === 'https:' ? 'wss:' : 'ws:'); +let testServerBaseUrl = new URL('../', window.location.href); +if (testServerBaseUrl.searchParams.has('server')) + testServerBaseUrl = new URL(testServerBaseUrl.searchParams.get('server')!, testServerBaseUrl); +const wsURL = new URL(searchParams.get('ws')!, testServerBaseUrl); +wsURL.protocol = (wsURL.protocol === 'https:' ? 'wss:' : 'ws:'); const queryParams = { args: searchParams.getAll('arg'), grep: searchParams.get('grep') || undefined,