playwright_patch
Execute an HTTP PATCH request to update web resources. Provide a URL and data payload to modify content directly within a browser environment.
Instructions
Perform an HTTP PATCH request
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | URL to perform PUT operation | |
| value | Yes | Data to PATCH in the body |
Implementation Reference
- src/tools/api/requests.ts:117-151 (handler)The PatchRequestTool class implements the core logic for executing HTTP PATCH requests using Playwright's API request context. It validates JSON input if applicable, sends the PATCH request, and returns status and truncated response.export class PatchRequestTool extends ApiToolBase { /** * Execute the PATCH request tool */ async execute(args: any, context: ToolContext): Promise<ToolResponse> { return this.safeExecute(context, async (apiContext) => { // Check if the value is valid JSON if it starts with { or [ if (args.value && typeof args.value === 'string' && (args.value.startsWith('{') || args.value.startsWith('['))) { try { JSON.parse(args.value); } catch (error) { return createErrorResponse(`Failed to parse request body: ${(error as Error).message}`); } } const response = await apiContext.patch(args.url, { data: args.value }); let responseText; try { responseText = await response.text(); } catch (error) { responseText = "Unable to get response text"; } return createSuccessResponse([ `PATCH request to ${args.url}`, `Status: ${response.status()} ${response.statusText()}`, `Response: ${responseText.substring(0, 1000)}${responseText.length > 1000 ? '...' : ''}` ]); }); } }
- src/tools.ts:259-270 (schema)Tool schema definition including name, description, and input schema requiring 'url' and 'value' parameters.{ name: "playwright_patch", description: "Perform an HTTP PATCH request", inputSchema: { type: "object", properties: { url: { type: "string", description: "URL to perform PUT operation" }, value: { type: "string", description: "Data to PATCH in the body" }, }, required: ["url", "value"], }, },
- src/toolHandler.ts:511-512 (registration)Registration in the main tool handler switch statement that routes 'playwright_patch' calls to the PatchRequestTool's execute method.case "playwright_patch": return await patchRequestTool.execute(args, context);
- src/toolHandler.ts:307-307 (registration)Initialization of the PatchRequestTool instance in the initializeTools function.if (!patchRequestTool) patchRequestTool = new PatchRequestTool(server);
- src/tools/api/base.ts:1-29 (helper)ApiToolBase class provides the base functionality including safeExecute method used by PatchRequestTool for handling API context and error management.import type { APIRequestContext } from "rebrowser-playwright"; import { ToolHandler, ToolContext, ToolResponse, createErrorResponse, } from "../common/types.js"; /** * Base class for all API-based tools * Provides common functionality and error handling */ export abstract class ApiToolBase implements ToolHandler { protected server: any; constructor(server: any) { this.server = server; } /** * Main execution method that all tools must implement */ abstract execute(args: any, context: ToolContext): Promise<ToolResponse>; /** * Ensures an API context is available and returns it * @param context The tool context containing apiContext * @returns The apiContext or null if not available */