Implementation:Microsoft Playwright Protocol Validator
| Knowledge Sources | |
|---|---|
| Domains | Protocol, Validation |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Auto-generated protocol validation schema that defines runtime type validators for every message in Playwright's internal client-server protocol.
Description
This file (~2,998 lines) is generated by generate_channels.js and builds a comprehensive validation schema for all protocol messages exchanged between the Playwright client and server processes. It uses a declarative approach where each protocol message type (params and results) is defined as a schema entry using primitive validator combinators.
The file imports and re-exports core validation infrastructure from validatorPrimitives:
import { scheme, tOptional, tObject, tBoolean, tInt, tFloat, tString, tAny, tEnum, tArray, tBinary, tChannel, tType } from './validatorPrimitives';
export type { Validator, ValidatorContext } from './validatorPrimitives';
export { ValidationError, findValidator, maybeFindValidator, createMetadataValidator } from './validatorPrimitives';
Key schema definitions include:
- Primitive types:
StackFrame,Metadata,Point,Rect,SerializedValue - Channel schemas: Params and Result schemas for every protocol method (e.g.,
scheme.BrowserTypeLaunchParams,scheme.PageGotoResult) - Compound types:
SetNetworkCookie,URLPattern,ExpectedTextValue,SelectorEngine
Each schema entry uses validator combinators:
// Example: StackFrame schema
scheme.StackFrame = tObject({
file: tString,
line: tInt,
column: tInt,
function: tOptional(tString),
});
// Example: Metadata schema
scheme.Metadata = tObject({
location: tOptional(tObject({
file: tString,
line: tOptional(tInt),
column: tOptional(tInt),
})),
title: tOptional(tString),
internal: tOptional(tBoolean),
stepId: tOptional(tString),
});
The schema covers all protocol domains including Browser, BrowserContext, Page, Frame, ElementHandle, Network, Dialog, Worker, CDPSession, Electron, Android, and PageAgent.
Usage
The validators are used at runtime to validate protocol messages crossing the client-server boundary. When a client sends a request or the server sends a response, the corresponding schema is looked up via findValidator() and the message payload is validated against it. This catches type mismatches, missing required fields, and invalid enum values before they cause downstream errors.
Code Reference
Source Location
- Repository: Microsoft_Playwright
- File:
packages/playwright-core/src/protocol/validator.ts
Import
import { findValidator, maybeFindValidator, createMetadataValidator, ValidationError } from './validator';
import type { Validator, ValidatorContext } from './validator';
Generation
# This file is auto-generated; do not edit manually
# Generated by: generate_channels.js