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 Server Instrumentation

From Leeroopedia

Template:Implementation Page

Overview

Server Instrumentation defines the base SDK object hierarchy and instrumentation interface for Playwright's server-side components, providing event tracking, attribution, and lifecycle management.

Description

This module defines two core abstractions:

  • SdkObject -- the base class for all server-side Playwright objects (pages, contexts, browsers, etc.). Each SdkObject has a unique GUID, attribution metadata linking it to its parent Playwright/browser/context/page, and an instrumentation reference for event callbacks.
  • Instrumentation interface -- defines lifecycle callbacks (onBrowserOpen, onPageOpen, onCallLog, etc.) that enable tracing, logging, and debugging across the entire Playwright server.

The Attribution type captures the full hierarchy chain from Playwright root to the current object.

Usage

All Playwright server objects extend SdkObject. The instrumentation system is used internally for tracing, the debug controller, and API call logging.

Code Reference

Source Location

packages/playwright-core/src/server/instrumentation.ts (122 lines)

Class Signature

export class SdkObject<EM extends EventMap = EventMap> extends EventEmitter<EM> {
  guid: string;
  attribution: Attribution;
  instrumentation: Instrumentation;
  logName?: LogName;
  constructor(parent: SdkObject, guidPrefix?: string, guid?: string)
  closeReason(): string | undefined
}

export type Attribution = {
  playwright: Playwright;
  browserType?: BrowserType;
  browser?: Browser;
  context?: BrowserContext | APIRequestContext;
  page?: Page;
  frame?: Frame;
};

Import

import { SdkObject, createRootSdkObject } from './server/instrumentation';
import type { CallMetadata, Attribution, Instrumentation } from './server/instrumentation';

I/O Contract

Inputs

  • parent: SdkObject -- parent object whose attribution is inherited
  • guidPrefix: string -- optional prefix for the generated GUID
  • guid: string -- optional explicit GUID

Outputs

  • Unique guid for object identification
  • Inherited attribution chain
  • Access to instrumentation callbacks

Related Pages

Page Connections

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