Implementation:Microsoft Playwright WkWorkers
Appearance
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
WKSessionthat 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 workerssession: WKSession-- the page session for worker event listeners
Outputs
- Creates
Workerinstances registered on the page - Establishes execution contexts for each worker
- Handles console message forwarding
Related Pages
- Microsoft_Playwright_WkConnection -- WebKit sessions used for worker communication
- Microsoft_Playwright_WkExecutionContext -- Execution context for workers
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment