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 WkWorkers

From Leeroopedia

Template:Implementation Page

Overview

WKWorkers manages Web Worker lifecycle for WebKit pages, creating worker sessions, execution contexts, and handling console messages from workers.

Description

The WKWorkers class listens for WebKit Worker.workerCreated and Worker.workerTerminated events to manage the lifecycle of web workers within a page. For each worker:

  • Creates a WKSession that proxies messages through the parent session
  • Establishes an execution context using WKExecutionContext
  • Enables Runtime and Console protocol domains
  • Forwards console messages from workers to the page
  • Cleans up sessions and workers on termination or page navigation

Usage

Created internally per WebKit page. Workers are tracked and accessible through the page's worker API.

Code Reference

Source Location

packages/playwright-core/src/server/webkit/wkWorkers.ts (109 lines)

Class Signature

export class WKWorkers {
  constructor(page: Page)
  setSession(session: WKSession): void
  clear(): void
}

Import

import { WKWorkers } from './server/webkit/wkWorkers';

I/O Contract

Inputs

  • page: Page -- the parent page owning the workers
  • session: WKSession -- the page session for worker event listeners

Outputs

  • Creates Worker instances registered on the page
  • Establishes execution contexts for each worker
  • Handles console message forwarding

Related Pages

Page Connections

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