Implementation:Microsoft Playwright BidiExecutionContext
| Knowledge Sources | |
|---|---|
| Domains | BiDi, JavaScript |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for evaluating JavaScript expressions and calling functions within a BiDi browser execution context provided by the Playwright library.
Description
The `BidiExecutionContext` class implements the `js.ExecutionContextDelegate` interface for the WebDriver BiDi protocol. It wraps a `BidiSession` and a target (either a browsing context with optional sandbox, or a realm). The class provides `rawEvaluateJSON` for simple expression evaluation returning JSON values, `rawEvaluateHandle` for expressions returning remote object handles, and `evaluateWithArguments` for calling functions with serialized arguments via `script.callFunction`. It uses `BidiSerializer` for argument serialization and `deserializeBidiValue` for result deserialization.
Usage
Use BidiExecutionContext when Playwright needs to evaluate JavaScript in a BiDi-connected browser page, frame, or worker context.
Code Reference
Source Location
- Repository: Microsoft_Playwright
- File: packages/playwright-core/src/server/bidi/bidiExecutionContext.ts
Signature
export class BidiExecutionContext implements js.ExecutionContextDelegate {
private readonly _session: BidiSession;
readonly _target: bidi.Script.Target;
constructor(session: BidiSession, realmInfo: bidi.Script.RealmInfo);
async rawEvaluateJSON(expression: string): Promise<any>;
async rawEvaluateHandle(context: js.ExecutionContext, expression: string): Promise<js.JSHandle>;
async evaluateWithArguments(expression: string, returnByValue: boolean, utilityScript: js.JSHandle, values: any[], handles: js.JSHandle[]): Promise<any>;
}
Import
import { BidiExecutionContext } from '../server/bidi/bidiExecutionContext';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| session | BidiSession | Yes | The BiDi session used to send commands |
| realmInfo | bidi.Script.RealmInfo | Yes | Realm information identifying the execution context |
| expression | string | Yes | JavaScript expression or function body to evaluate |
| values | any[] | No | Serialized argument values for function calls |
| handles | js.JSHandle[] | No | Remote object handle arguments for function calls |
Outputs
| Name | Type | Description |
|---|---|---|
| result | any | Deserialized evaluation result value |
| handle | js.JSHandle | Remote handle to the evaluation result |
Usage Examples
import { BidiExecutionContext } from '../server/bidi/bidiExecutionContext';
const execContext = new BidiExecutionContext(bidiSession, realmInfo);
const title = await execContext.rawEvaluateJSON('document.title');
const handle = await execContext.rawEvaluateHandle(context, 'document.body');