Implementation:Webdriverio Webdriverio WebDriver Types
| Knowledge Sources | |
|---|---|
| Domains | WebDriver, Type_Definitions |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
The WebDriver_Types module defines the core TypeScript interfaces, types, and classes for the WebDriver client, including session state flags, client configuration, Bidi command/response types, and runtime command options.
Description
This module provides the foundational type definitions for the WebDriver package. JSONWPCommandError extends Error with optional code, statusCode, and statusMessage fields for JSONWP error handling. SessionFlags is an interface with boolean flags for all environment detection properties: isW3C, isChromium, isFirefox, isAndroid, isMobile, isNativeContext, isIOS, isSauce, isSeleniumStandalone, isBidi, isWindowsApp, and isMacApp, along with a mobileContext string.
BaseClient combines EventEmitter and SessionFlags with sessionId, capabilities, requestedCapabilities, and options. Client is the full client type that intersects BaseClient, ProtocolCommands, BidiHandler, and BidiEventHandler. AttachOptions provides the shape for attaching to an existing session.
The module derives computed types from the protocol definitions: BidiCommands extracts command names from the WebDriver Bidi protocol, BidiResponses resolves the return types of those commands, and EventMap maps event method names to their parameter types, combining Bidi events with classic WebDriver events (command, result, bidiCommand, bidiResult, and request lifecycle events).
CommandRuntimeOptions is a class (not just an interface) to enable instanceof detection in the command factory, currently supporting a mask boolean option for sensitive data masking.
Usage
Use these types throughout the WebDriver package for type-safe client interactions, session management, and event handling. They are the primary type contracts for the public API surface.
Code Reference
Source Location
- Repository: Webdriverio_Webdriverio
- File: packages/webdriver/src/types.ts
Signature
export interface JSONWPCommandError extends Error {
code?: string
statusCode?: string
statusMessage?: string
}
export interface SessionFlags {
isW3C: boolean
isChromium: boolean
isFirefox: boolean
isAndroid: boolean
isMobile: boolean
isNativeContext: boolean
mobileContext: string | undefined
isIOS: boolean
isSauce: boolean
isSeleniumStandalone: boolean
isBidi: boolean
isWindowsApp: boolean
isMacApp: boolean
}
export interface BaseClient extends EventEmitter, SessionFlags {
sessionId: string
capabilities: WebdriverIO.Capabilities
requestedCapabilities: Capabilities.WithRequestedCapabilities['capabilities']
options: Options.WebDriver
}
export interface Client extends Omit<BaseClient, keyof BidiEventHandler>,
ProtocolCommands, BidiHandler, BidiEventHandler {}
export interface AttachOptions extends Partial<SessionFlags>, Partial<Options.WebDriver> {
sessionId: string
capabilities?: WebdriverIO.Capabilities
requestedCapabilities?: Capabilities.WithRequestedCapabilities['capabilities']
}
export type BidiCommands = WebDriverBidiCommands[keyof WebDriverBidiCommands]['socket']['command']
export type BidiResponses = ValueOf<ObtainMethods<Pick<BidiHandler, BidiCommands>>>
export type RemoteConfig = Options.WebDriver & Capabilities.WithRequestedCapabilities
export type EventMap = {
[Event in EventData['method']]: GetParam<EventData, Event>
} & WebDriverClassicEvents
export class CommandRuntimeOptions {
mask?: boolean
constructor(options: { mask?: boolean })
}
Import
import type { Client, BaseClient, SessionFlags, JSONWPCommandError, AttachOptions, BidiCommands, BidiResponses, RemoteConfig, EventMap } from './types.js'
import { CommandRuntimeOptions } from './types.js'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| N/A | N/A | N/A | This is primarily a type-only module. The only runtime export is CommandRuntimeOptions.
|
| options (CommandRuntimeOptions) | { mask?: boolean } |
Yes | Options object for constructing runtime command options. |
Outputs
| Name | Type | Description |
|---|---|---|
| SessionFlags | interface |
Boolean flags identifying the browser/platform environment of the session. |
| BaseClient | interface |
Core client interface with session ID, capabilities, and options. |
| Client | interface |
Full client type including all protocol commands, Bidi handler, and typed event handlers. |
| AttachOptions | interface |
Options for attaching to an existing WebDriver session. |
| BidiCommands | type |
Union of all Bidi command name strings extracted from the protocol definition. |
| BidiResponses | type |
Union of all Bidi command return types. |
| EventMap | type |
Complete event map combining Bidi events and classic WebDriver events. |
| CommandRuntimeOptions | class |
Runtime options class with mask property, detectable via instanceof.
|
Usage Examples
import type { Client, SessionFlags, EventMap } from './types.js'
import { CommandRuntimeOptions } from './types.js'
// Use SessionFlags for environment detection
function logEnvironment(flags: SessionFlags) {
if (flags.isBidi) {
console.log('Bidi session is active');
}
if (flags.isMobile) {
console.log('Running on mobile device');
}
}
// Use CommandRuntimeOptions for sensitive data masking
const runtimeOpts = new CommandRuntimeOptions({ mask: true });
await browser.setValue('#password', 'secret123', runtimeOpts);
// Type-safe event handling
const client: Client = browser as unknown as Client;
client.on('browsingContext.navigationStarted', (params) => {
console.log(`Navigating to: ${params.url}`);
});
client.on('network.responseCompleted', (params) => {
console.log(`Response: ${params.response.status} ${params.response.url}`);
});