Implementation:Microsoft Playwright LocalUtilsDispatcher
| Knowledge Sources | |
|---|---|
| Domains | Dispatcher, Utilities |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for exposing local utility functions (HAR management, device descriptors, network operations) over the Playwright RPC protocol provided by the Playwright library.
Description
The `LocalUtilsDispatcher` class extends `Dispatcher` and implements `channels.LocalUtilsChannel` to provide a collection of utility operations that run on the client's local machine. It exposes device descriptors in its initializer, and provides methods for: `zip` (creating trace archives), `harOpen`/`harLookup`/`harClose`/`harUnzip` (HAR file management), `connect` (establishing WebSocket connections to remote browsers via `JsonPipeDispatcher`), `addStackToTracingNoReply`/`tracing` (stack session management), and `globToRegex`/`resolveGlobToRegexPattern` (glob pattern conversion). It maintains maps of `HarBackend` instances and `StackSession` instances for stateful operations.
Usage
Use LocalUtilsDispatcher when the protocol layer needs to expose local-only utility operations to the Playwright client, including HAR replay, trace packaging, and device information.
Code Reference
Source Location
- Repository: Microsoft_Playwright
- File: packages/playwright-core/src/server/dispatchers/localUtilsDispatcher.ts
Signature
export class LocalUtilsDispatcher extends Dispatcher<SdkObject, channels.LocalUtilsChannel, RootDispatcher> implements channels.LocalUtilsChannel {
_type_LocalUtils: boolean;
constructor(scope: RootDispatcher, playwright: Playwright);
async zip(params: channels.LocalUtilsZipParams, progress: Progress): Promise<void>;
async harOpen(params: channels.LocalUtilsHarOpenParams, progress: Progress): Promise<channels.LocalUtilsHarOpenResult>;
async harLookup(params: channels.LocalUtilsHarLookupParams, progress: Progress): Promise<channels.LocalUtilsHarLookupResult>;
async harClose(params: channels.LocalUtilsHarCloseParams, progress: Progress): Promise<void>;
async harUnzip(params: channels.LocalUtilsHarUnzipParams, progress: Progress): Promise<void>;
async connect(params: channels.LocalUtilsConnectParams, progress: Progress): Promise<channels.LocalUtilsConnectResult>;
}
Import
import { LocalUtilsDispatcher } from '../server/dispatchers/localUtilsDispatcher';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| scope | RootDispatcher | Yes | Root dispatcher scope |
| playwright | Playwright | Yes | The Playwright instance for device descriptors |
| params | various channel params | Yes | Method-specific parameters (paths, URLs, options) |
Outputs
| Name | Type | Description |
|---|---|---|
| harId | string | Identifier for an opened HAR backend |
| pipe | JsonPipeDispatcher | WebSocket pipe for remote browser connection |
| deviceDescriptors | DeviceDescriptor[] | Array of device emulation descriptors |
Usage Examples
import { LocalUtilsDispatcher } from '../server/dispatchers/localUtilsDispatcher';
const utils = new LocalUtilsDispatcher(rootScope, playwright);
const { harId } = await utils.harOpen({ file: '/path/to/recording.har' }, progress);
const { action, redirectURL } = await utils.harLookup({ harId, url: 'https://example.com/api', method: 'GET' }, progress);