page_callMethod
Call a method exposed on the current page instance. Pass method name and arguments as an array to execute page-specific functions.
Instructions
调用当前页面实例上暴露的方法。参数可以作为数组提供。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| connection | No | ||
| method | Yes | ||
| args | No |
Implementation Reference
- src/tools/page.ts:339-370 (handler)Function that creates the 'page_callMethod' tool. The execute handler calls page.callMethod(args.method, ...callArgs) and returns the result.
function createCallPageMethodTool(manager: WeappAutomatorManager): AnyTool { return { name: "page_callMethod", description: "调用当前页面实例上暴露的方法。参数可以作为数组提供。", parameters: callPageMethodParameters, execute: async (rawArgs, context: ToolContext) => withUserErrorResult(async () => { const args = callPageMethodParameters.parse(rawArgs ?? {}); const callArgs = args.args ?? []; return manager.withPage<ContentResult>( context.log, { overrides: args.connection }, async (page) => { let result; try { result = await page.callMethod(args.method, ...callArgs); } catch (error) { const message = error instanceof Error ? error.message : String(error); throw new UserError(`调用页面方法 "${args.method}" 失败: ${message}`); } return toTextResult( formatJson({ method: args.method, arguments: callArgs, result: toSerializableValue(result), }) ); } ); }), }; } - src/tools/page.ts:26-29 (schema)Zod schema for the 'page_callMethod' tool parameters: 'method' (required string) and 'args' (optional array of unknown values).
const callPageMethodParameters = connectionContainerSchema.extend({ method: z.string().trim().min(1), args: z.array(z.unknown()).optional(), }); - src/tools/page.ts:52-61 (registration)The 'page_callMethod' tool is registered via createCallPageMethodTool(manager) in the createPageTools array export.
export function createPageTools(manager: WeappAutomatorManager): AnyTool[] { return [ createGetElementTool(manager), createGetElementsTool(manager), createWaitForElementTool(manager), createWaitForTimeoutTool(manager), createGetPageDataTool(manager), createSetPageDataTool(manager), createCallPageMethodTool(manager), ];