Skip to main content
Glama

tauri_webview_wait_for

Read-only

Wait for elements, text, or IPC events in Tauri app webviews during UI automation and testing. Specify selectors, content, or event names with timeout control.

Instructions

[Tauri Apps Only] Wait for elements, text, or IPC events in a Tauri app. Requires active tauri_driver_session. Targets the only connected app, or the default app if multiple are connected. Specify appIdentifier (port or bundle ID) to target a specific app. For browser waits, use Chrome DevTools MCP instead.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
windowIdNoWindow label to target (defaults to "main")
appIdentifierNoApp port or bundle ID to target. Defaults to the only connected app or the default app if multiple are connected.
typeYesWhat to wait for
valueYesSelector, text content, or IPC event name to wait for
timeoutNoTimeout in milliseconds (default: 5000ms)

Implementation Reference

  • Core handler function that builds the wait script using buildScript and SCRIPTS.waitFor, then executes it in the target webview window via executeInWebview.
    export async function waitFor(options: WaitForOptions): Promise<string> {
       const { type, value, timeout = 5000, windowId, appIdentifier } = options;
    
       const script = buildScript(SCRIPTS.waitFor, { type, value, timeout });
    
       try {
          return await executeInWebview(script, windowId, appIdentifier);
       } catch(error: unknown) {
          const message = error instanceof Error ? error.message : String(error);
    
          throw new Error(`Wait failed: ${message}`);
       }
    }
  • Zod schema for validating input parameters: type (selector/text/ipc-event), value, timeout, plus inherited windowId/appIdentifier.
    export const WaitForSchema = WindowTargetSchema.extend({
       type: z.enum([ 'selector', 'text', 'ipc-event' ]).describe('What to wait for'),
       value: z.string().describe('Selector, text content, or IPC event name to wait for'),
       timeout: z.number().optional().default(5000).describe('Timeout in milliseconds (default: 5000ms)'),
    });
  • Tool registration in the central TOOLS array, including description, category, schema reference, annotations, and thin wrapper handler that parses args and delegates to the waitFor implementation.
    {
       name: 'tauri_webview_wait_for',
       description:
          '[Tauri Apps Only] Wait for elements, text, or IPC events in a Tauri app. ' +
          'Requires active tauri_driver_session. ' +
          MULTI_APP_DESC + ' ' +
          'For browser waits, use Chrome DevTools MCP instead.',
       category: TOOL_CATEGORIES.UI_AUTOMATION,
       schema: WaitForSchema,
       annotations: {
          title: 'Wait for Condition in Tauri',
          readOnlyHint: true,
          openWorldHint: false,
       },
       handler: async (args) => {
          const parsed = WaitForSchema.parse(args);
    
          return await waitFor({
             type: parsed.type,
             value: parsed.value,
             timeout: parsed.timeout,
             windowId: parsed.windowId,
             appIdentifier: parsed.appIdentifier,
          });
       },
    },
  • Injected JavaScript script (SCRIPTS.waitFor) that implements the polling logic: checks every 100ms for selector existence or text presence in document.body.innerText, resolves with success message or rejects on timeout.
    /**
     * Wait for conditions script - waits for selectors, text, or events
     *
     * @param {Object} params
     * @param {string} params.type - What to wait for: 'selector', 'text', 'ipc-event'
     * @param {string} params.value - Selector, text, or event name to wait for
     * @param {number} params.timeout - Timeout in milliseconds
     */
    (async function(params) {
       const { type, value, timeout } = params;
       const startTime = Date.now();
    
       return new Promise((resolve, reject) => {
          function check() {
             if (Date.now() - startTime > timeout) {
                reject(new Error(`Timeout waiting for ${type}: ${value}`));
                return;
             }
    
             if (type === 'selector') {
                const element = document.querySelector(value);
                if (element) {
                   resolve(`Element found: ${value}`);
                   return;
                }
             } else if (type === 'text') {
                const found = document.body.innerText.includes(value);
                if (found) {
                   resolve(`Text found: ${value}`);
                   return;
                }
             } else if (type === 'ipc-event') {
                // For IPC events, we'd need to set up a listener
                // This is a simplified version
                reject(new Error('IPC event waiting not yet implemented in this context'));
                return;
             }
    
             setTimeout(check, 100);
          }
    
          check();
       });
    })
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations indicate readOnlyHint=true and openWorldHint=false, which the description aligns with by not implying any destructive actions. The description adds valuable context beyond annotations: it specifies the prerequisite of an active tauri_driver_session, clarifies targeting rules for apps, and mentions a timeout default (though this is also in the schema). However, it lacks details on error handling or return values, which could enhance transparency further.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with key information (purpose and prerequisites) in the first sentence, followed by targeting details and an alternative recommendation. Every sentence earns its place by adding necessary context without redundancy, resulting in a compact and well-structured text.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (5 parameters, no output schema) and rich annotations, the description is largely complete: it covers purpose, prerequisites, targeting, and alternatives. However, it does not explain what happens on timeout or success (e.g., return values or behavior), which could be useful since there's no output schema. This minor gap prevents a perfect score.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds minimal semantic value beyond the schema, such as implying the 'type' parameter's options (selector, text, ipc-event) and mentioning app targeting, but does not provide additional syntax or usage examples. This meets the baseline of 3 for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('Wait for elements, text, or IPC events') and resource ('in a Tauri app'), distinguishing it from siblings like tauri_webview_interact or tauri_ipc_monitor by focusing on waiting rather than interaction or monitoring. It explicitly mentions the requirement for an active tauri_driver_session, adding specificity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use this tool vs. alternatives: it specifies '[Tauri Apps Only]' as a prerequisite, mentions the need for an active tauri_driver_session, and advises 'For browser waits, use Chrome DevTools MCP instead.' It also clarifies targeting behavior for single vs. multiple connected apps, offering clear context and exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/hypothesi/mcp-server-tauri'

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