Repository: microsoft/playwright
File: packages/playwright-core/src/server/trace/viewer/traceViewer.ts (TypeScript)

Code before:
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import fs from 'fs';
import path from 'path';

import { gracefullyProcessExitDoNotHang } from '../../../utils';
import { isUnderTest } from '../../../utils';
import { HttpServer } from '../../utils/httpServer';
import { open } from '../../../utilsBundle';
import { syncLocalStorageWithSettings } from '../../launchApp';
import { launchApp } from '../../launchApp';
import { createPlaywright } from '../../playwright';
import { ProgressController } from '../../progress';

import type { Transport } from '../../utils/httpServer';
import type { BrowserType } from '../../browserType';
import type { Page } from '../../page';
import type http from 'http';
import type { Readable } from 'stream';

export type TraceViewerServerOptions = {
  host?: string;
  port?: number;
  stdin?: Readable;
  transport?: Transport;
};

export type TraceViewerRedirectOptions = {
  args?: string[];
  grep?: string;
  grepInvert?: string;
  project?: string[];
  reporter?: string[];
  webApp?: string;
  stdin?: Readable;
};

export type TraceViewerAppOptions = {
  headless?: boolean;
  persistentContextOptions?: Parameters<BrowserType['launchPersistentContext']>[2];
};

const tracesDirMarker = 'traces.dir';

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

  if (traceFileOrUrl.startsWith('http://') || traceFileOrUrl.startsWith('https://'))

Review comment (suggestion):
This can be imported via `playwright-core/server`. I suspect we only have it for testing purposes, and it's not part of our public API to anyone.

Code after:
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import fs from 'fs';
import path from 'path';

import { gracefullyProcessExitDoNotHang } from '../../../utils';
import { isUnderTest } from '../../../utils';
import { HttpServer } from '../../utils/httpServer';
import { open } from '../../../utilsBundle';
import { syncLocalStorageWithSettings } from '../../launchApp';
import { launchApp } from '../../launchApp';
import { createPlaywright } from '../../playwright';
import { ProgressController } from '../../progress';

import type { Transport } from '../../utils/httpServer';
import type { BrowserType } from '../../browserType';
import type { Page } from '../../page';
import type http from 'http';

export type TraceViewerServerOptions = {
  host?: string;
  port?: number;
  isServer?: boolean;
  transport?: Transport;
};

export type TraceViewerRedirectOptions = {
  args?: string[];
  grep?: string;
  grepInvert?: string;
  project?: string[];
  reporter?: string[];
  webApp?: string;
  isServer?: boolean;
};

export type TraceViewerAppOptions = {
  headless?: boolean;
  persistentContextOptions?: Parameters<BrowserType['launchPersistentContext']>[2];
};

const tracesDirMarker = 'traces.dir';

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

  if (traceFileOrUrl.startsWith('http://') || traceFileOrUrl.startsWith('https://'))
    return traceFileOrUrl;