Skip to main content
Glama

webview_wait_for

Read-only

Wait for a UI element, text content, or IPC event in a Tauri app webview. Supports CSS, XPath, and text strategies with configurable timeout and window target.

Instructions

[Tauri Apps Only] Wait for elements, text, or IPC events in a Tauri app. When type is "selector", supports CSS (default), XPath, and text strategies via the strategy parameter. Requires active 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
strategyNoSelector strategy (applies when type is "selector"): "css" (default), "xpath", or "text".css
timeoutNoTimeout in milliseconds (default: 5000ms)

Implementation Reference

  • Registration of the 'webview_wait_for' tool in the tools registry, with description, schema reference (WaitForSchema), and handler that delegates to the waitFor function.
    {
       name: 'webview_wait_for',
       description:
          '[Tauri Apps Only] Wait for elements, text, or IPC events in a Tauri app. ' +
          'When type is "selector", supports CSS (default), XPath, and text strategies via the strategy parameter. ' +
          'Requires active 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,
             strategy: parsed.strategy,
             timeout: parsed.timeout,
             windowId: parsed.windowId,
             appIdentifier: parsed.appIdentifier,
          });
       },
    },
  • Zod schema WaitForSchema defining the input validation for webview_wait_for: type (selector/text/ipc-event), value, strategy, timeout, 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'),
       strategy: selectorStrategyField.describe(
          'Selector strategy (applies when type is "selector"): "css" (default), "xpath", or "text".'
       ),
       timeout: z.number().optional().default(5000).describe('Timeout in milliseconds (default: 5000ms)'),
    });
  • The waitFor function (WaitForOptions interface + implementation) that builds the wait-for script and executes it in the webview via executeInWebview.
    export interface WaitForOptions {
       type: string;
       value: string;
       strategy?: string;
       timeout?: number;
       windowId?: string;
       appIdentifier?: string | number;
    }
    
    export async function waitFor(options: WaitForOptions): Promise<string> {
       const { type, value, strategy, timeout = 5000, windowId, appIdentifier } = options;
    
       const script = buildScript(SCRIPTS.waitFor, { type, value, strategy: strategy ?? 'css', 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}`);
       }
    }
  • SCRIPTS constant loading the wait-for.js script as the 'waitFor' entry, used by buildScript to create injected code.
    export const SCRIPTS = {
       resolveRef: loadScript('resolve-ref'),
       interact: loadScript('interact'),
       swipe: loadScript('swipe'),
       keyboard: loadScript('keyboard'),
       waitFor: loadScript('wait-for'),
       getStyles: loadScript('get-styles'),
       focus: loadScript('focus'),
       findElement: loadScript('find-element'),
       domSnapshot: loadScript('dom-snapshot'),
       elementPicker: loadScript('element-picker'),
    } as const;
  • The actual injected JavaScript IIFE that executes in the webview to poll for selectors, text content, or IPC events until 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/ref ID, text, or event name to wait for
     * @param {string} params.strategy - Selector strategy (applies when type is 'selector'): 'css', 'xpath', or 'text'
     * @param {number} params.timeout - Timeout in milliseconds
     */
    (async function(params) {
       const { type, value, strategy, timeout } = params;
       const startTime = Date.now();
    
       function resolveElement(selectorOrRef) {
          if (!selectorOrRef) return null;
          return window.__MCP__.resolveRef(selectorOrRef, strategy);
       }
    
       return new Promise(function(resolve, reject) {
          function check() {
             if (Date.now() - startTime > timeout) {
                reject(new Error('Timeout waiting for ' + type + ': ' + value));
                return;
             }
    
             if (type === 'selector') {
                var element = resolveElement(value);
                if (element) {
                   var msg = 'Element found: ' + value;
                   var count = window.__MCP__.countAll(value, strategy);
                   if (count > 1) msg += ' (+' + (count - 1) + ' more match' + (count - 1 === 1 ? '' : 'es') + ')';
                   resolve(msg);
                   return;
                }
             } else if (type === 'text') {
                var 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 already indicate read-only. The description adds context about requiring a driver session and targeting apps, but does not detail timeout behavior or return value.

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?

Description is 5 sentences with no redundancy, front-loaded with core purpose. Every sentence serves a purpose.

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?

The tool has 6 params and no output schema. Description explains key usage but could mention what the tool returns after waiting.

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

Parameters4/5

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

Schema covers 100% parameters. The description clarifies the relationship between 'type', 'strategy', and 'appIdentifier', adding value beyond schema descriptions.

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 waits for elements, text, or IPC events in a Tauri app, with explicit mention of the platform and alternative for browser waits.

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 specifies prerequisites (active driver_session), target selection logic, and provides an explicit alternative for browser waits, guiding appropriate use.

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