always operate on absolute urls

This commit is contained in:
Simon Knott 2024-10-29 13:32:46 +01:00
parent 28a0aa420b
commit 4bdd5105e4
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
2 changed files with 18 additions and 13 deletions

View file

@ -31,7 +31,7 @@ export class ZipTraceModelBackend implements TraceModelBackend {
constructor(traceURL: string, progress: Progress) {
this._traceURL = traceURL;
this._zipReader = new zipjs.ZipReader(
new zipjs.HttpReader(formatUrl(traceURL), { mode: 'cors', preventHeadRequest: true } as any),
new zipjs.HttpReader(traceURL, { mode: 'cors', preventHeadRequest: true } as any),
{ useWebWorkers: false });
this._entriesPromise = this._zipReader.getEntries({ onprogress: progress }).then(entries => {
const map = new Map<string, zip.Entry>();
@ -134,11 +134,3 @@ export class FetchTraceModelBackend implements TraceModelBackend {
return fetch(fileURL);
}
}
function formatUrl(trace: string) {
let url = trace;
// Dropbox does not support cors.
if (url.startsWith('https://www.dropbox.com/'))
url = 'https://dl.dropboxusercontent.com/' + url.substring('https://www.dropbox.com/'.length);
return url;
}

View file

@ -54,7 +54,7 @@ export const TraceView: React.FC<{
// Test finished.
const attachment = result && result.duration >= 0 && result.attachments.find(a => a.name === 'trace');
if (attachment && attachment.path) {
loadSingleTraceFile(attachment.path).then(model => setModel({ model, isLive: false }));
loadSingleTraceFile(new URL(attachment.path, 'file://')).then(model => setModel({ model, isLive: false }));
return;
}
@ -72,7 +72,7 @@ export const TraceView: React.FC<{
// Start polling running test.
pollTimer.current = setTimeout(async () => {
try {
const model = await loadSingleTraceFile(traceLocation);
const model = await loadSingleTraceFile(new URL(traceLocation, 'file://'));
setModel({ model, isLive: true });
} catch {
setModel(undefined);
@ -108,11 +108,24 @@ const outputDirForTestCase = (testCase: reporterTypes.TestCase): string | undefi
return undefined;
};
async function loadSingleTraceFile(url: string): Promise<MultiTraceModel> {
async function loadSingleTraceFile(tracePathOrURL: URL): Promise<MultiTraceModel> {
const params = new URLSearchParams();
params.set('trace', url);
params.set('trace', formatUrl(tracePathOrURL).toString());
params.set('limit', '1');
const response = await fetch(`contexts?${params.toString()}`);
const contextEntries = await response.json() as ContextEntry[];
return new MultiTraceModel(contextEntries);
}
function formatUrl(tracePathOrURL: URL) {
if (tracePathOrURL.protocol === 'file:') {
const url = new URL('/trace/file', location.href);
url.searchParams.set('path', tracePathOrURL.pathname);
return url;
}
if (tracePathOrURL.hostname === 'dropbox.com')
tracePathOrURL.hostname = 'dl.dropboxusercontent.com';
return tracePathOrURL;
}