page_callMethod
Execute methods exposed on current page instances within WeChat Mini Program development, passing parameters as arrays for automated testing and interaction.
Instructions
调用当前页面实例上暴露的方法。参数可以作为数组提供。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| connection | No | ||
| method | Yes | ||
| args | No |
Implementation Reference
- src/tools/page.ts:166-183 (handler)The execute handler function for the 'page_callMethod' tool. Parses input arguments using the schema, invokes page.callMethod with the method name and arguments via the manager, and returns a formatted JSON response containing the method, arguments, and result.execute: async (rawArgs, context: ToolContext) => { const args = callPageMethodParameters.parse(rawArgs ?? {}); const callArgs = args.args ?? []; return manager.withPage<ContentResult>( context.log, { overrides: args.connection }, async (page) => { const result = await page.callMethod(args.method, ...callArgs); return toTextResult( formatJson({ method: args.method, arguments: callArgs, result: toSerializableValue(result), }) ); } ); },
- src/tools/page.ts:24-27 (schema)Zod schema defining the input parameters for the 'page_callMethod' tool: 'method' (required string) and 'args' (optional array of any values), extending connectionContainerSchema.const callPageMethodParameters = connectionContainerSchema.extend({ method: z.string().trim().min(1), args: z.array(z.unknown()).optional(), });
- src/tools/page.ts:42-51 (registration)Registration of the 'page_callMethod' tool within the createPageTools function, which creates and returns an array of page-related tools including page_callMethod.export function createPageTools(manager: WeappAutomatorManager): AnyTool[] { return [ createGetElementTool(manager), createWaitForElementTool(manager), createWaitForTimeoutTool(manager), createGetPageDataTool(manager), createSetPageDataTool(manager), createCallPageMethodTool(manager), ]; }
- src/tools.ts:7-13 (registration)Higher-level registration where createPageTools (including page_callMethod) is incorporated into the main createTools function that aggregates all tools.export function createTools(manager: WeappAutomatorManager): AnyTool[] { return [ ...createApplicationTools(manager), ...createPageTools(manager), ...createElementTools(manager), ]; }