Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/playwright-core/src/server/trace/viewer/traceViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export type TraceViewerAppOptions = {

const tracesDirMarker = 'traces.dir';

function validateTraceUrl(traceFileOrUrl: string | undefined): string | undefined {
function validateTraceUrlOrPath(traceFileOrUrl: string | undefined): string | undefined {
if (!traceFileOrUrl)
return traceFileOrUrl;

Expand Down Expand Up @@ -152,7 +152,7 @@ export async function installRootRedirect(server: HttpServer, traceUrl: string |
}

export async function runTraceViewerApp(traceUrl: string | undefined, browserName: string, options: TraceViewerServerOptions & { headless?: boolean }, exitOnClose?: boolean) {
traceUrl = validateTraceUrl(traceUrl);
traceUrl = validateTraceUrlOrPath(traceUrl);
const server = await startTraceViewerServer(options);
await installRootRedirect(server, traceUrl, options);
const page = await openTraceViewerApp(server.urlPrefix('precise'), browserName, options);
Expand All @@ -162,7 +162,7 @@ export async function runTraceViewerApp(traceUrl: string | undefined, browserNam
}

export async function runTraceInBrowser(traceUrl: string | undefined, options: TraceViewerServerOptions) {
traceUrl = validateTraceUrl(traceUrl);
traceUrl = validateTraceUrlOrPath(traceUrl);
const server = await startTraceViewerServer(options);
await installRootRedirect(server, traceUrl, options);
await openTraceInBrowser(server.urlPrefix('human-readable'));
Expand Down Expand Up @@ -216,8 +216,8 @@ class StdinServer implements Transport {

constructor() {
process.stdin.on('data', data => {
const url = data.toString().trim();
if (url === this._traceUrl)
const url = validateTraceUrlOrPath(data.toString().trim());
if (!url || url === this._traceUrl)
return;
if (url.endsWith('.json'))
this._pollLoadTrace(url);
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/utils/httpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class HttpServer {
this._port = address.port;
const resolvedHost = address.family === 'IPv4' ? address.address : `[${address.address}]`;
this._urlPrefixPrecise = `http://${resolvedHost}:${address.port}`;
this._urlPrefixHumanReadable = `http://${host}:${address.port}`;
this._urlPrefixHumanReadable = `http://${host ?? 'localhost'}:${address.port}`;
}
}

Expand Down
13 changes: 13 additions & 0 deletions tests/library/trace-viewer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2248,3 +2248,16 @@ test('should capture iframe with srcdoc', async ({ page, server, runAndTrace })
const frame = await traceViewer.snapshotFrame('Evaluate');
await expect(frame.frameLocator('iframe').getByRole('button')).toHaveText('Hello iframe');
});

test('take trace paths via stdin', async ({ childProcess, page }) => {
const cliEntrypoint = path.join(__dirname, '../../packages/playwright-core/cli.js');
const cp = childProcess({ command: ['node', cliEntrypoint, 'show-trace', '--port', '0', '--stdin'] });
await cp.waitForOutput('Listening on');
const url = cp.output.match(/Listening on (http:\/\/[^\s]+)/)![1];
await page.goto(url);
await expect(page).toHaveTitle('Playwright Trace Viewer');
cp.write(traceFile);
await expect(page.locator('.action-title')).toContainText([
/Create page/,
]);
});
Loading