Implementation:Microsoft Playwright Server Instrumentation
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.
Instrumentationinterface -- 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 inheritedguidPrefix: string-- optional prefix for the generated GUIDguid: string-- optional explicit GUID
Outputs
- Unique
guidfor object identification - Inherited
attributionchain - Access to
instrumentationcallbacks
Related Pages
- Microsoft_Playwright_Server_Playwright -- Root Playwright object extending SdkObject
- Microsoft_Playwright_ProgressController -- Uses instrumentation for call logging
- Microsoft_Playwright_DebugLogger -- Debug logging integration