mastra-ai/mastra · error · Error

Mouse event injection not supported by this provider

Error message

Mouse event injection not supported by this provider

What it means

injectMouseEvent is a base-class stub that providers override when they can inject pointer input (e.g. via CDP Input.dispatchMouseEvent). The default implementation always throws, advertising the provider's lack of input-injection support.

Source

Thrown at packages/core/src/browser/browser.ts:1503

        `[MastraBrowser] startScreencastIfBrowserActive: hasThreadSession(${threadId})=false, scope=${scope}`,
      );
      return null;
    }

    return this.startScreencast(mergedOptions);
  }

  // ---------------------------------------------------------------------------
  // Event Injection (optional - for Studio live view)
  // ---------------------------------------------------------------------------

  /**
   * Inject a mouse event. Override in subclass if supported.
   * @param event - Mouse event parameters
   * @param threadId - Optional thread ID for thread-isolated sessions
   */
  async injectMouseEvent(_event: MouseEventParams, _threadId?: string): Promise<void> {
    throw new Error('Mouse event injection not supported by this provider');
  }

  /**
   * Inject a keyboard event. Override in subclass if supported.
   * @param event - Keyboard event parameters
   * @param threadId - Optional thread ID for thread-isolated sessions
   */
  async injectKeyboardEvent(_event: KeyboardEventParams, _threadId?: string): Promise<void> {
    throw new Error('Keyboard event injection not supported by this provider');
  }

  // ---------------------------------------------------------------------------
  // Abstract Methods (providers must implement)
  // ---------------------------------------------------------------------------

  /**
   * Get the active page for a thread.
   * Used by screencast reconnection to emit the current URL.

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Use a provider that implements injectMouseEvent.
  2. Feature-detect capability before calling and degrade (e.g. use playwright page.mouse directly if the session object is exposed).
  3. Implement the override in a custom provider.
  4. Model the interaction via higher-level automation APIs the provider does support.

Example fix

// before
await browser.injectMouseEvent({ type: 'mousePressed', x: 10, y: 10 });
// after
const cdp = await browser.getPage(sessionId);
await cdp.send('Input.dispatchMouseEvent', { type: 'mousePressed', x: 10, y: 10 });
Defensive patterns

Strategy: validation

Validate before calling

if (browser.injectMouseEvent === MastraBrowser.prototype.injectMouseEvent) {
  throw new Error(`Provider ${browser.provider} cannot inject mouse events`);
}

Type guard

function supportsMouseInput(b: object): boolean {
  return b.injectMouseEvent !== MastraBrowser.prototype.injectMouseEvent;
}

Try / catch

try {
  await browser.injectMouseEvent(ev, threadId);
} catch (err) {
  if (err instanceof Error && err.message.includes('Mouse event injection not supported')) {
    await fallbackClick(page, ev); // e.g. DOM-level click via page handle
  } else throw err;
}

Prevention

When it happens

Trigger: Calling browser.injectMouseEvent(event, threadId?) on a provider that has not overridden the method.

Common situations: Simulating user clicks in an agent loop against a provider without input injection; replaying recorded interaction traces across providers with different capability sets.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/f58c0925fd7de2fd. Report an issue: GitHub.