Implementation:Microsoft Playwright WkExecutionContext
Overview
WKExecutionContext implements the JavaScript execution context delegate for WebKit, enabling expression evaluation and function calls within WebKit browser pages through the WebKit Inspector Protocol.
Description
The WKExecutionContext class implements js.ExecutionContextDelegate, bridging Playwright's abstract execution API with WebKit's Runtime domain. It supports:
- Evaluating expressions returning JSON values (
rawEvaluateJSON) - Evaluating expressions returning object handles (
rawEvaluateHandle) - Calling functions with serialized arguments (
evaluateWithArguments) - Managing remote object references and garbage collection (
releaseHandle)
Error handling translates WebKit-specific exceptions into standard Playwright JavaScript evaluation errors.
Usage
Created internally by the WebKit page implementation for each execution context in frames and workers.
Code Reference
Source Location
packages/playwright-core/src/server/webkit/wkExecutionContext.ts (149 lines)
Class Signature
export class WKExecutionContext implements js.ExecutionContextDelegate {
constructor(session: WKSession, contextId: number | undefined)
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 { WKExecutionContext, createHandle } from './server/webkit/wkExecutionContext';
I/O Contract
Inputs
session: WKSession-- WebKit protocol sessioncontextId: number | undefined-- execution context identifier (undefined for default)
Outputs
- JSON values or
JSHandlereferences from evaluations - Throws
JavaScriptErrorInEvaluatefor evaluation failures
Related Pages
- Microsoft_Playwright_WkConnection -- WebKit session management
- Microsoft_Playwright_FfExecutionContext -- Firefox equivalent