Skip to main content
Glama

tauri_webview_wait_for

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(); }); })

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