Implementation:Microsoft Playwright BidiCommands Types
| Knowledge Sources | |
|---|---|
| Domains | BiDi, TypeDefinitions |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for defining the typed command interface for WebDriver BiDi protocol methods provided by the Playwright library.
Description
The `bidiCommands.d.ts` type definition file declares the `Commands` interface that maps BiDi protocol method names to their parameter and return types. Each entry specifies a `params` type and a `returnType`, providing full type safety for BiDi command invocations via `BidiSession.send()`. The interface covers all BiDi domains: `script` (evaluate, callFunction, disown, addPreloadScript, removePreloadScript), `browser` (close, createUserContext, getUserContexts, removeUserContext), `browsingContext` (activate, create, close, navigate, reload, print, setViewport, traverseHistory, handleUserPrompt, captureScreenshot), `network` (addIntercept, removeIntercept, continueRequest, continueResponse, continueWithAuth, failRequest, provideResponse, setCacheBehavior), `storage` (getCookies, setCookie, deleteCookies), and `input` (performActions).
Usage
Use BidiCommands Types when sending typed BiDi commands through `BidiSession.send()` to ensure compile-time type checking of parameters and return values.
Code Reference
Source Location
- Repository: Microsoft_Playwright
- File: packages/playwright-core/src/server/bidi/third_party/bidiCommands.d.ts
Signature
export interface Commands {
'script.evaluate': {
params: Bidi.Script.EvaluateParameters;
returnType: Bidi.Script.EvaluateResult;
};
'script.callFunction': {
params: Bidi.Script.CallFunctionParameters;
returnType: Bidi.Script.EvaluateResult;
};
'browser.close': {
params: Bidi.EmptyParams;
returnType: Bidi.EmptyResult;
};
'browsingContext.create': {
params: Bidi.BrowsingContext.CreateParameters;
returnType: Bidi.BrowsingContext.CreateResult;
};
// ... additional commands for all BiDi domains
}
Import
import type * as bidiCommands from '../server/bidi/third_party/bidiCommands';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| (type-only) | N/A | N/A | This is a type definition file with no runtime inputs |
Outputs
| Name | Type | Description |
|---|---|---|
| Commands | interface | Type map from BiDi method names to params/returnType pairs |
Usage Examples
import type * as bidiCommands from './third_party/bidiCommands';
// Type-safe command sending
async function send<T extends keyof bidiCommands.Commands>(
method: T,
params: bidiCommands.Commands[T]['params']
): Promise<bidiCommands.Commands[T]['returnType']> {
// implementation
}
const result = await send('script.evaluate', {
expression: 'document.title',
target: { context: 'ctx-id' },
awaitPromise: true,
});