Appium Webapp Communication Bug

We have a multi-platform (iOS, Android, desktop, etc.) web application with information that is passed between the native/frame layer and the webview/JavaScript layer. On the Android version of our app: After navigating the webview to a different, locally hosted html file, we’re encountering an issue where messages being sent from the frame to the webview seem to be lost.

The scenario is as follows:
After we successfully navigate the webview to the new html file, we execute a series of calls from JavaScript to the frame, with the frame response triggering another message to the frame as a callback, and so on. (i.e. JavaScript sends a call to frame, frame does something and sends the response back to JavaScript, JavaScript registers that it has received a response to a call it made and sends another call…etc.). Running our webapp with Appium, one of a series of the frame responses to the webview (frame sending a message to JavaScript) is failing to go through.

According to our logs, the frame successfully calls the JavaScript function which handles messages, but the corresponding JavaScript function never logs that it has received a message. We log immediately when a message is sent on the frame side and on the JavaScript side when any message reaches that function; it appears as if the message just disappears after the frame ‘calls’ the JavaScript function.

The end result is that the webview hangs waiting on the expected response from the frame. Our application is not failing on a single call repeatedly, but rather one of a set of interlinked calls that occur during in a period of time. Manually re-sending the original call from JavaScript to the frame fixes the issue. Additionally, changing the screen orientation, causing us to rebuild the webview, which also fixes the issue. We can’t replicate the issue outside of building our app with Appium, so we suspect it is causing some interference with our communication.

HERE IS THE APPIUM CODE
@Test
public void Test1() throws InterruptedException{

	    Thread.sleep(15000);
	    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
	
	    Set<String> contextNames = driver.getContextHandles();
        for (String contextName : contextNames) {
          System.out.println(contextName);
          if (contextName.contains("WEBVIEW")){
            driver.context(contextName);
          }
        }
    
        //more options
  	    waitForElementPresent(By.cssSelector("div[data-collect='true']"), 40);
        driver.findElement(By.cssSelector("div[data-collect='true']")).click();

//THIS IS WHERE THE APP HANGS UP AND THE NEXT SCREEN WITH THE LINK BELOW NEVER COMES UP
//sign in
waitForElementPresent(By.id(“wizard_link_sign_in”), 40);
driver.findElement(By.id(“wizard_link_sign_in”)).click();