Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Microsoft Playwright FileUtils

From Leeroopedia

Template:Implementation Page

Overview

FileUtils provides file system utility functions for common operations like directory creation, file removal, path sanitization, and zip file creation used throughout Playwright's server code.

Description

This module exports a collection of file system helpers:

  • existsAsync -- async file existence check
  • mkdirIfNeeded -- creates parent directories recursively for a file path
  • removeFolders -- recursively removes multiple directories in parallel
  • canAccessFile -- synchronous file accessibility check
  • copyFileAndMakeWritable -- copies a file and sets writable permissions
  • sanitizeForFilePath -- removes unsafe characters from path components
  • toPosixPath -- converts platform-specific paths to POSIX format
  • addZipFile -- adds files to zip archives using yazl

Usage

Used throughout the codebase for file operations, temporary directory management, and artifact storage.

Code Reference

Source Location

packages/playwright-core/src/server/utils/fileUtils.ts (205 lines)

Function Signatures

export const existsAsync: (path: string) => Promise<boolean>;
export async function mkdirIfNeeded(filePath: string): Promise<void>;
export async function removeFolders(dirs: string[]): Promise<(Error | undefined)[]>;
export function canAccessFile(file: string): boolean;
export async function copyFileAndMakeWritable(from: string, to: string): Promise<void>;
export function sanitizeForFilePath(s: string): string;
export function toPosixPath(aPath: string): string;

Import

import { mkdirIfNeeded, removeFolders, canAccessFile, sanitizeForFilePath } from './server/utils/fileUtils';

I/O Contract

Key Behaviors

  • mkdirIfNeeded silently ignores errors (e.g., root directory on Windows)
  • removeFolders uses maxRetries: 10 for resilience on Windows
  • sanitizeForFilePath replaces control characters and special characters with hyphens

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment