Implementation:Microsoft Playwright LocalUtils
Overview
LocalUtils provides server-side utility functions for trace file management, HAR operations, and zip file creation used by the Playwright test runner and trace viewer.
Description
This module exports utility functions that operate on the local filesystem for:
- Zip creation -- packages trace files, source code, and call stack metadata into zip archives for trace storage
- HAR management -- interfaces with
HarBackendfor HTTP Archive operations - Stack session tracking -- manages call stack metadata across test sessions for inclusion in trace files
The StackSession type tracks per-file trace writers and their associated call stack data, supporting both live and completed sessions.
Usage
Used internally by the Playwright test runner to create trace zip files and manage HAR recordings.
Code Reference
Source Location
packages/playwright-core/src/server/localUtils.ts (216 lines)
Function Signatures
export async function zip(
progress: Progress,
stackSessions: Map<string, StackSession>,
params: channels.LocalUtilsZipParams
): Promise<void>
export type StackSession = {
file: string;
writer: Promise<void>;
tmpDir: string | undefined;
callStacks: channels.ClientSideCallMetadata[];
live?: boolean;
};
Import
import { zip } from './server/localUtils';
import type { StackSession } from './server/localUtils';
I/O Contract
Inputs
progress: Progress-- progress reporting interfacestackSessions: Map-- map of session file paths to stack session dataparams: LocalUtilsZipParams-- zip parameters including file entries
Outputs
- Creates a zip file on disk containing trace data, source files, and call stack metadata
- Resolves the returned promise when zip creation is complete
Related Pages
- Microsoft_Playwright_FileUtils -- File system utility functions
- Microsoft_Playwright_CryptoUtils -- SHA1 calculation for file hashing
- Microsoft_Playwright_ManualPromise -- Promise utilities used for async coordination