Skip to main content
Glama
pvinis
by pvinis

playwright_expect_response

Initiate waiting for a specific HTTP response in Playwright by specifying a unique ID and URL pattern. Later, retrieve and validate the response using the Playwright_assert_response tool.

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

  • ExpectResponseTool class with execute method that initiates page.waitForResponse(url) and stores the promise in a map keyed by the provided id.
    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}`
          );
        });
      }
    }
  • Tool schema definition specifying input parameters 'id' (string) and 'url' (string).
    {
      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"],
      },
    },
  • Registration in the main tool handler switch statement, delegating execution to ExpectResponseTool instance.
    case "playwright_expect_response":
      return await expectResponseTool.execute(args, context);
  • Instantiation of the ExpectResponseTool class instance used by the handler.
    if (!expectResponseTool) expectResponseTool = new ExpectResponseTool(server);
  • Helper method in codegen generator to produce Playwright test code for this tool.
    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/pvinis/mcp-playwright-stealth'

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