Skip to content

[Bug]: aiTap intermittently fails on Android WebView (first tap after page navigation not registered) #2927

Description

@H-M-Master

Version

Version:
  System:
    OS: macOS 26.6
    CPU: (12) arm64 Apple M4 Pro
    Memory: 264.39 MB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  npmPackages:
    @midscene/android: 1.10.1 => 1.10.1

Details

Details:

Description

When running multiple test cases sequentially on a remote Android device (WeTest cloud),
the first aiTap after a page navigation sometimes fails to register — the AI correctly
identifies the element position, the ADB command is sent to the correct coordinates,
but the tap has no effect on the app. A second tap on the same coordinates always succeeds.

Environment

  • Device: Samsung SM-S9480, Android 16 (API 36)
  • App: Native Android app with embedded WebView pages
  • Connection: Remote device via WeTest (ADB over network)
  • Model: qwen3-vl

Reproduce link

This issue requires a remote Android device with network-forwarded ADB and a WebView-based app to reproduce. A minimal public reproduction is ▎ not feasible due to infrastructure requirements. Happy to provide CI logs and Midscene reports if needed.

Reproduce Steps

Steps to Reproduce

  1. Use agentFromAdbDevice to connect
  2. Navigate to a page via deeplink (am start -a android.intent.action.VIEW -d ...)
  3. Wait for page to fully load (10s sleep, page confirmed loaded in screenshot)
  4. Call agent.aiTap('click some button')
  5. The tap does NOT register (page state unchanged)
  6. Call the same aiTap again → succeeds immediately

This only happens:

  • When running multiple tests sequentially (single test always passes)
  • On remote/cloud devices (local device rarely reproduces)
  • After deeplink-based page navigation

Workaround

Sending input keyevent 0 (KEYCODE_UNKNOWN) after page navigation and before the first
aiTap resolves the issue — it appears to "wake up" the WebView's touch event handling.

await agent.runAdbShell('input keyevent 0');
await agent.aiTap('...');  // now works on first try

Analysis

From the Midscene report, the AI localization is correct and the tap coordinates are accurate.
The issue seems to be at the ADB input delivery level.

I noticed Midscene uses input swipe x y x y 150 to simulate taps.
Could this 150ms swipe-at-same-point approach be handled differently by WebViews
that haven't received input focus yet? A raw input tap x y or the input keyevent 0
pre-warming might behave differently at the OS level for focus acquisition.

Expected Behavior

aiTap should reliably trigger the tap on the first call when the element is correctly
identified and the page is fully loaded.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions