chore(trace viewer): support HMR (#33609)
This commit is contained in:
parent
a14d9750b3
commit
ed2be67e47
|
@ -125,7 +125,13 @@ export async function installRootRedirect(server: HttpServer, traceUrls: string[
|
||||||
for (const reporter of options.reporter || [])
|
for (const reporter of options.reporter || [])
|
||||||
params.append('reporter', reporter);
|
params.append('reporter', reporter);
|
||||||
|
|
||||||
const urlPath = `./trace/${options.webApp || 'index.html'}?${params.toString()}`;
|
let baseUrl = '.';
|
||||||
|
if (process.env.PW_HMR) {
|
||||||
|
baseUrl = 'http://localhost:44223'; // port is hardcoded in build.js
|
||||||
|
params.set('server', server.urlPrefix('precise'));
|
||||||
|
}
|
||||||
|
|
||||||
|
const urlPath = `${baseUrl}/trace/${options.webApp || 'index.html'}?${params.toString()}`;
|
||||||
server.routePath('/', (_, response) => {
|
server.routePath('/', (_, response) => {
|
||||||
response.statusCode = 302;
|
response.statusCode = 302;
|
||||||
response.setHeader('Location', urlPath);
|
response.setHeader('Location', urlPath);
|
||||||
|
|
|
@ -43,10 +43,8 @@ async function loadTrace(traceUrl: string, traceFileName: string | null, client:
|
||||||
const clientId = client?.id ?? '';
|
const clientId = client?.id ?? '';
|
||||||
let data = clientIdToTraceUrls.get(clientId);
|
let data = clientIdToTraceUrls.get(clientId);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
let traceViewerServerBaseUrl = new URL('../', client?.url ?? self.registration.scope);
|
const clientURL = new URL(client?.url ?? self.registration.scope);
|
||||||
if (traceViewerServerBaseUrl.searchParams.has('server'))
|
const traceViewerServerBaseUrl = new URL(clientURL.searchParams.get('server') ?? '../', clientURL);
|
||||||
traceViewerServerBaseUrl = new URL(traceViewerServerBaseUrl.searchParams.get('server')!, traceViewerServerBaseUrl);
|
|
||||||
|
|
||||||
data = { limit, traceUrls: new Set(), traceViewerServer: new TraceViewerServer(traceViewerServerBaseUrl) };
|
data = { limit, traceUrls: new Set(), traceViewerServer: new TraceViewerServer(traceViewerServerBaseUrl) };
|
||||||
clientIdToTraceUrls.set(clientId, data);
|
clientIdToTraceUrls.set(clientId, data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -344,7 +344,8 @@ export function extendSnapshot(snapshot: Snapshot): SnapshotUrls {
|
||||||
|
|
||||||
const popoutParams = new URLSearchParams();
|
const popoutParams = new URLSearchParams();
|
||||||
popoutParams.set('r', snapshotUrl);
|
popoutParams.set('r', snapshotUrl);
|
||||||
popoutParams.set('server', serverParam ?? '');
|
if (serverParam)
|
||||||
|
popoutParams.set('server', serverParam);
|
||||||
popoutParams.set('trace', context(snapshot.action).traceUrl);
|
popoutParams.set('trace', context(snapshot.action).traceUrl);
|
||||||
if (snapshot.point) {
|
if (snapshot.point) {
|
||||||
popoutParams.set('pointX', String(snapshot.point.x));
|
popoutParams.set('pointX', String(snapshot.point.x));
|
||||||
|
|
|
@ -47,9 +47,7 @@ const xtermDataSource: XtermDataSource = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const searchParams = new URLSearchParams(window.location.search);
|
const searchParams = new URLSearchParams(window.location.search);
|
||||||
let testServerBaseUrl = new URL('../', window.location.href);
|
const testServerBaseUrl = new URL(searchParams.get('server') ?? '../', window.location.href);
|
||||||
if (testServerBaseUrl.searchParams.has('server'))
|
|
||||||
testServerBaseUrl = new URL(testServerBaseUrl.searchParams.get('server')!, testServerBaseUrl);
|
|
||||||
const wsURL = new URL(searchParams.get('ws')!, testServerBaseUrl);
|
const wsURL = new URL(searchParams.get('ws')!, testServerBaseUrl);
|
||||||
wsURL.protocol = (wsURL.protocol === 'https:' ? 'wss:' : 'ws:');
|
wsURL.protocol = (wsURL.protocol === 'https:' ? 'wss:' : 'ws:');
|
||||||
const queryParams = {
|
const queryParams = {
|
||||||
|
|
Loading…
Reference in New Issue