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 ProgressController

From Leeroopedia

Template:Implementation Page

Overview

ProgressController manages the lifecycle of asynchronous operations in Playwright, providing timeout management, abort capabilities, and structured logging for API calls.

Description

The ProgressController class wraps async tasks with timeout handling, abort signals, and state tracking. It transitions through states: before, running, error, and finished. Tasks receive a Progress object for logging and timeout access. The controller supports:

  • Timeout-based cancellation using AbortController
  • Forced abort via the abort() method
  • Call metadata tracking for tracing and debugging
  • Structured logging through the onCallLog callback
  • Static factory methods for internal tasks

Usage

Used throughout Playwright server code to wrap operations that need timeout and progress tracking.

Code Reference

Source Location

packages/playwright-core/src/server/progress.ts (147 lines)

Class Signature

export class ProgressController {
  readonly metadata: CallMetadata;
  constructor(metadata?: CallMetadata, onCallLog?: (message: string) => void)
  static createForSdkObject(sdkObject: SdkObject, callMetadata: CallMetadata): ProgressController
  static runInternalTask(task: (progress: Progress) => Promise<void>, timeout?: number): Promise<void>
  async abort(error: Error): Promise<void>
  async run<T>(task: (progress: Progress) => Promise<T>, timeout?: number): Promise<T>
}

Import

import { ProgressController } from './server/progress';
import type { Progress } from './server/progress';

I/O Contract

Inputs

  • metadata: CallMetadata -- optional metadata for the API call
  • onCallLog: (message: string) => void -- optional logging callback
  • task: (progress: Progress) => Promise<T> -- the async task to execute
  • timeout: number -- optional timeout in milliseconds

Outputs

  • Returns the task's result on success
  • Throws TimeoutError on timeout
  • Throws abort error if abort() is called

Usage Examples

Running a Task with Timeout

const controller = new ProgressController(metadata);
const result = await controller.run(async progress => {
  progress.log('Starting operation...');
  return await someAsyncOperation();
}, 30000);

Related Pages

Page Connections

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