mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
feat(trace): support loading trace from zip (#6551)
This commit is contained in:
parent
a7ea00d02e
commit
17e9dd95f7
@ -18,12 +18,14 @@
|
|||||||
|
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
|
|
||||||
import path from 'path';
|
import extract from 'extract-zip';
|
||||||
import program from 'commander';
|
|
||||||
import os from 'os';
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import os from 'os';
|
||||||
|
import path from 'path';
|
||||||
|
import rimraf from 'rimraf';
|
||||||
|
import program from 'commander';
|
||||||
import { runDriver, runServer, printApiJson, launchBrowserServer, installBrowsers } from './driver';
|
import { runDriver, runServer, printApiJson, launchBrowserServer, installBrowsers } from './driver';
|
||||||
import { showTraceViewer } from '../server/trace/viewer/traceViewer';
|
import { TraceViewer } from '../server/trace/viewer/traceViewer';
|
||||||
import * as playwright from '../..';
|
import * as playwright from '../..';
|
||||||
import { BrowserContext } from '../client/browserContext';
|
import { BrowserContext } from '../client/browserContext';
|
||||||
import { Browser } from '../client/browser';
|
import { Browser } from '../client/browser';
|
||||||
@ -475,3 +477,31 @@ function commandWithOpenOptions(command: string, description: string, options: a
|
|||||||
.option('--user-agent <ua string>', 'specify user agent string')
|
.option('--user-agent <ua string>', 'specify user agent string')
|
||||||
.option('--viewport-size <size>', 'specify browser viewport size in pixels, for example "1280, 720"');
|
.option('--viewport-size <size>', 'specify browser viewport size in pixels, for example "1280, 720"');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function showTraceViewer(tracePath: string, browserName: string) {
|
||||||
|
let stat;
|
||||||
|
try {
|
||||||
|
stat = fs.statSync(tracePath);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(`No such file or directory: ${tracePath}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stat.isDirectory()) {
|
||||||
|
const traceViewer = new TraceViewer(tracePath, browserName);
|
||||||
|
await traceViewer.show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const zipFile = tracePath;
|
||||||
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), `playwright-trace`));
|
||||||
|
process.on('exit', () => rimraf.sync(dir));
|
||||||
|
try {
|
||||||
|
await extract(zipFile, { dir: dir });
|
||||||
|
} catch (e) {
|
||||||
|
console.log(`Invalid trace file: ${zipFile}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const traceViewer = new TraceViewer(dir, browserName);
|
||||||
|
await traceViewer.show();
|
||||||
|
}
|
||||||
|
|||||||
@ -29,7 +29,7 @@ import { ProgressController } from '../../progress';
|
|||||||
|
|
||||||
const fsReadFileAsync = util.promisify(fs.readFile.bind(fs));
|
const fsReadFileAsync = util.promisify(fs.readFile.bind(fs));
|
||||||
|
|
||||||
class TraceViewer {
|
export class TraceViewer {
|
||||||
private _server: HttpServer;
|
private _server: HttpServer;
|
||||||
private _browserName: string;
|
private _browserName: string;
|
||||||
|
|
||||||
@ -144,8 +144,3 @@ class TraceViewer {
|
|||||||
await page.mainFrame().goto(internalCallMetadata(), urlPrefix + '/traceviewer/traceViewer/index.html');
|
await page.mainFrame().goto(internalCallMetadata(), urlPrefix + '/traceviewer/traceViewer/index.html');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function showTraceViewer(traceDir: string, browserName: string) {
|
|
||||||
const traceViewer = new TraceViewer(traceDir, browserName);
|
|
||||||
await traceViewer.show();
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user