From 814bf0d3113d3bfb64d8f105bc35e2c29cca4ccb Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Thu, 7 Nov 2024 15:19:07 +0100 Subject: [PATCH] revert all non-build changes --- .../src/server/trace/viewer/traceViewer.ts | 9 +-------- packages/trace-viewer/src/sw/main.ts | 3 +-- packages/trace-viewer/src/ui/sourceTab.tsx | 3 +-- packages/trace-viewer/src/ui/uiModeTraceView.tsx | 3 +-- packages/trace-viewer/src/ui/uiModeView.tsx | 7 +++---- 5 files changed, 7 insertions(+), 18 deletions(-) diff --git a/packages/playwright-core/src/server/trace/viewer/traceViewer.ts b/packages/playwright-core/src/server/trace/viewer/traceViewer.ts index 7fccbc3ec2..cc404c18ba 100644 --- a/packages/playwright-core/src/server/trace/viewer/traceViewer.ts +++ b/packages/playwright-core/src/server/trace/viewer/traceViewer.ts @@ -134,14 +134,7 @@ export async function installRootRedirect(server: HttpServer, traceUrls: string[ for (const reporter of options.reporter || []) params.append('reporter', reporter); - let baseUrl = ''; - if (process.env.PW_HMR === '1') { - params.set('testServerPort', '' + server.port()); - baseUrl = 'http://localhost:44223'; // port is hardcoded in build.js - } - - const urlPath = `${baseUrl}/trace/${options.webApp || 'index.html'}?${params.toString()}`; - + const urlPath = `./trace/${options.webApp || 'index.html'}?${params.toString()}`; server.routePath('/', (_, response) => { response.statusCode = 302; response.setHeader('Location', urlPath); diff --git a/packages/trace-viewer/src/sw/main.ts b/packages/trace-viewer/src/sw/main.ts index e23e5b1247..6fcb08daa7 100644 --- a/packages/trace-viewer/src/sw/main.ts +++ b/packages/trace-viewer/src/sw/main.ts @@ -85,8 +85,7 @@ async function doFetch(event: FetchEvent): Promise { // the https urls. const isDeployedAsHttps = self.registration.scope.startsWith('https://'); - // test server runs on a different port in HMR mode, so we only look at the hostname - if (new URL(request.url).hostname === new URL(self.registration.scope).hostname) { + if (request.url.startsWith(self.registration.scope)) { const url = new URL(unwrapPopoutUrl(request.url)); const relativePath = url.pathname.substring(scopePath.length - 1); if (relativePath === '/ping') { diff --git a/packages/trace-viewer/src/ui/sourceTab.tsx b/packages/trace-viewer/src/ui/sourceTab.tsx index b5a444d8de..1dd9170f67 100644 --- a/packages/trace-viewer/src/ui/sourceTab.tsx +++ b/packages/trace-viewer/src/ui/sourceTab.tsx @@ -26,7 +26,6 @@ import type { StackFrame } from '@protocol/channels'; import { CopyToClipboard } from './copyToClipboard'; import { ToolbarButton } from '@web/components/toolbarButton'; import { Toolbar } from '@web/components/toolbar'; -import { filePathToTraceURL } from './uiModeTraceView'; export const SourceTab: React.FunctionComponent<{ stack?: StackFrame[], @@ -74,7 +73,7 @@ export const SourceTab: React.FunctionComponent<{ try { let response = await fetch(`sha1/src@${sha1}.txt`); if (response.status === 404) - response = await fetch(filePathToTraceURL(file)); + response = await fetch(`file?path=${encodeURIComponent(file)}`); if (response.status >= 400) source.content = ``; else diff --git a/packages/trace-viewer/src/ui/uiModeTraceView.tsx b/packages/trace-viewer/src/ui/uiModeTraceView.tsx index 2b592ab6a6..8e98a8ccd7 100644 --- a/packages/trace-viewer/src/ui/uiModeTraceView.tsx +++ b/packages/trace-viewer/src/ui/uiModeTraceView.tsx @@ -24,7 +24,6 @@ import type { ContextEntry } from '../types/entries'; import type { SourceLocation } from './modelUtil'; import { MultiTraceModel } from './modelUtil'; import { Workbench } from './workbench'; -import { testServerBaseURL } from './uiModeView'; export const TraceView: React.FC<{ item: { treeItem?: TreeItem, testFile?: SourceLocation, testCase?: reporterTypes.TestCase }, @@ -127,7 +126,7 @@ function formatUrl(traceURL: URL) { } export function filePathToTraceURL(path: string) { - const url = new URL('file', testServerBaseURL); + const url = new URL('file', location.href); url.searchParams.set('path', path); return url; } diff --git a/packages/trace-viewer/src/ui/uiModeView.tsx b/packages/trace-viewer/src/ui/uiModeView.tsx index bffa3fc51a..69a5988641 100644 --- a/packages/trace-viewer/src/ui/uiModeView.tsx +++ b/packages/trace-viewer/src/ui/uiModeView.tsx @@ -46,10 +46,9 @@ const xtermDataSource: XtermDataSource = { resize: () => {}, }; -export const testServerBaseURL = new URL(window.location.href); -const searchParams = testServerBaseURL.searchParams; -testServerBaseURL.port = searchParams.get('testServerPort') ?? testServerBaseURL.port; -const wsURL = new URL(`/${searchParams.get('ws')}`, testServerBaseURL); +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:'); const queryParams = { args: searchParams.getAll('arg'),