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 WkExecutionContext

From Leeroopedia

Template:Implementation Page

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 session
  • contextId: number | undefined -- execution context identifier (undefined for default)

Outputs

  • JSON values or JSHandle references from evaluations
  • Throws JavaScriptErrorInEvaluate for evaluation failures

Related Pages

Page Connections

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