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 BidiSerializer

From Leeroopedia
Revision as of 11:35, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Microsoft_Playwright_BidiSerializer.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains BiDi, Serialization
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete tool for serializing JavaScript values into WebDriver BiDi local value format provided by the Playwright library.

Description

The `BidiSerializer` class provides a static `serialize` method that converts JavaScript values into `Bidi.Script.LocalValue` objects for transmission over the BiDi protocol. It handles all JavaScript primitive types (undefined, null, boolean, number, bigint, string) and complex types (objects, arrays, RegExp, Date). Special number values (-0, Infinity, -Infinity, NaN) are serialized as `SpecialNumber` strings. Objects and arrays are recursively serialized. An `UnserializableError` is thrown for symbols and functions. This is a third-party module originally from Puppeteer.

Usage

Use BidiSerializer when preparing JavaScript function arguments for BiDi `script.callFunction` commands, converting local values into the BiDi wire format.

Code Reference

Source Location

  • Repository: Microsoft_Playwright
  • File: packages/playwright-core/src/server/bidi/third_party/bidiSerializer.ts

Signature

export class BidiSerializer {
  static serialize(arg: unknown): Bidi.Script.LocalValue;
  static _serializeNumber(arg: number): Bidi.Script.LocalValue;
  static _serializeObject(arg: object | null): Bidi.Script.LocalValue;
}

Import

import { BidiSerializer } from '../server/bidi/third_party/bidiSerializer';

I/O Contract

Inputs

Name Type Required Description
arg unknown Yes The JavaScript value to serialize into BiDi format

Outputs

Name Type Description
result Bidi.Script.LocalValue The serialized BiDi local value representation

Usage Examples

import { BidiSerializer } from './third_party/bidiSerializer';

BidiSerializer.serialize('hello');   // { type: 'string', value: 'hello' }
BidiSerializer.serialize(42);        // { type: 'number', value: 42 }
BidiSerializer.serialize(null);      // { type: 'null' }
BidiSerializer.serialize(undefined); // { type: 'undefined' }
BidiSerializer.serialize([1, 2]);    // { type: 'array', value: [...] }
BidiSerializer.serialize(NaN);       // { type: 'number', value: 'NaN' }

Related Pages

Page Connections

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