capacitor-plugins icon indicating copy to clipboard operation
capacitor-plugins copied to clipboard

Capacitor.Plugins.App.getInfo sometimes does not complete (resolve/reject)

Open Mottschi opened this issue 1 year ago • 3 comments

Bug Report

Plugin(s)

App

Capacitor Version

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 6.2.0
  @capacitor/core: 6.2.0
  @capacitor/android: 6.2.0
  @capacitor/ios: 6.2.0

Installed Dependencies:

  @capacitor/ios: not installed
  @capacitor/cli: 6.2.0
  @capacitor/core: 6.2.0
  @capacitor/android: 6.2.0

[success] Android looking great! 👌

Platform(s)

Android

On physical devices, I was able to reproduce this on a Pixel 2XL running Android 11, but not on a Pixel 8A or Nothing Phone 1 running Android 14.

However, on Android Studio emulators, I was able to reproduce it on emulators running Android 13, 14 and 15.

Current Behavior

Calling Capacitor.Plugins.App.getInfo() during the DOMContentLoaded event of the index page sometimes does not resolve (nor reject), the promise simply never completes at all.

Expected Behavior

The getInfo function should either resolve or reject.

Code Reproduction

https://github.com/Mottschi/capacitor-android-reload

This example app will automatically reload until the issue is encountered, incrementing a counter to show progress. When the bug occurs, the reloads and counter incrementation will simply stop. Observed frequency the issue occurred was different depending on the device/emulator used, but generally, on the devices where it occurs, it happens the first time within about the first 100 reloads.

Other Technical Details

We did some debugging when we encountered this in our app. From what we were able to tell, the getInfo method in AppPlugin.java is called and resolves normally in these cases, but the result seems to be getting lost when being sent with postMessage through the androidBridge to JS.

Additional Context

Mottschi avatar Dec 11 '24 08:12 Mottschi

I was able to replicate this on Google Pixel 9 Pro XL. Any updates or workarounds for the meantime?

markhermano avatar Mar 04 '25 02:03 markhermano

We ended up using the following workaround:

const appInfo = await Promise.race([Capacitor.Plugins.App.getInfo(), Capacitor.Plugins.App.getInfo()])

Since the issue only occurs with the first call (at least from what we observed), this should guarantee that the app does not get stuck waiting for the getInfo to resolve/reject.

Mottschi avatar Mar 04 '25 12:03 Mottschi

We ended up using the following workaround:

const appInfo = await Promise.race([Capacitor.Plugins.App.getInfo(), Capacitor.Plugins.App.getInfo()])

Since the issue only occurs with the first call (at least from what we observed), this should guarantee that the app does not get stuck waiting for the getInfo to resolve/reject.

I also did a Promise.race but have the second promise to auto resolve a generic message within 5 seconds. Nice observation, I'll try that solution.

markhermano avatar Mar 04 '25 15:03 markhermano