playwright_expect_response
Initiate waiting for HTTP responses in browser automation tests to verify network interactions and validate expected API calls or page loads.
Instructions
Ask Playwright to start waiting for a HTTP response. This tool initiates the wait operation but does not wait for its completion.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Unique & arbitrary identifier to be used for retrieving this response later with `Playwright_assert_response`. | |
| url | Yes | URL pattern to match in the response. |
Implementation Reference
- src/tools/browser/response.ts:21-37 (handler)The ExpectResponseTool class implements the core logic for the 'playwright_expect_response' tool. It sets up a Playwright page.waitForResponse promise for the given URL and stores it in a map keyed by the provided ID for later retrieval.export class ExpectResponseTool extends BrowserToolBase { /** * Execute the expect response tool */ async execute(args: ExpectResponseArgs, context: ToolContext): Promise<ToolResponse> { return this.safeExecute(context, async (page) => { if (!args.id || !args.url) { return createErrorResponse("Missing required parameters: id and url must be provided"); } const responsePromise = page.waitForResponse(args.url); responsePromises.set(args.id, responsePromise); return createSuccessResponse(`Started waiting for response with ID ${args.id}`); }); } }
- src/tools.ts:337-353 (schema)Tool metadata including name, description, and input schema (JSON Schema) for 'playwright_expect_response'.{ name: "playwright_expect_response", description: "Ask Playwright to start waiting for a HTTP response. This tool initiates the wait operation but does not wait for its completion.", inputSchema: { type: "object", properties: { id: { type: "string", description: "Unique & arbitrary identifier to be used for retrieving this response later with `Playwright_assert_response`.", }, url: { type: "string", description: "URL pattern to match in the response." }, }, required: ["id", "url"], }, },
- src/toolHandler.ts:400-401 (registration)Instantiation of the ExpectResponseTool instance in the initializeTools function.if (!expectResponseTool) expectResponseTool = new ExpectResponseTool(server); if (!assertResponseTool) assertResponseTool = new AssertResponseTool(server);
- src/toolHandler.ts:609-610 (registration)Switch case in handleToolCall that dispatches execution to expectResponseTool.executecase "playwright_expect_response": return await expectResponseTool.execute(args, context);
- src/tools/browser/response.ts:6-7 (helper)Global map storing pending response promises by ID, used by both expect and assert tools.const responsePromises = new Map<string, Promise<Response>>();