Skip to main content
Glama
devskido

Playwright MCP Server

by devskido

playwright_expect_response

Initiate waiting for HTTP responses in browser automation tests by specifying URL patterns and unique identifiers for later validation.

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
NameRequiredDescriptionDefault
idYesUnique & arbitrary identifier to be used for retrieving this response later with `Playwright_assert_response`.
urlYesURL pattern to match in the response.

Implementation Reference

  • Implements the core execution logic for the 'playwright_expect_response' tool using Playwright's page.waitForResponse to start waiting for a HTTP response matching the URL pattern, storing the promise for later assertion.
    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}`);
        });
      }
    }
  • Defines the tool schema including name, description, input parameters (id and url), and validation requirements.
    {
      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"],
      },
    },
  • Registers the tool handler in the main tool dispatching switch statement, delegating execution to the ExpectResponseTool instance.
    case "playwright_expect_response":
      return await expectResponseTool.execute(args, context);
  • Instantiates the ExpectResponseTool class instance used for handling tool calls.
    if (!expectResponseTool) expectResponseTool = new ExpectResponseTool(server);
  • Generates equivalent Playwright test code for the tool action during codegen session recording.
    private generateExpectResponseStep(parameters: Record<string, unknown>): string {
      const { url, id } = parameters;
      return `
      // Wait for response
      const ${id}Response = page.waitForResponse('${url}');`;
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/devskido/customed-playwright'

If you have feedback or need assistance with the MCP directory API, please join our Discord server