Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin onload seems to start plugin before app ready #1715

Open
globules-io opened this issue May 30, 2024 · 2 comments
Open

plugin onload seems to start plugin before app ready #1715

globules-io opened this issue May 30, 2024 · 2 comments

Comments

@globules-io
Copy link

globules-io commented May 30, 2024

Bug Report

Problem

We use a firebasex plugin, which has been working fine but lately we have noticed an issue and believe it could be related to plugin initialization.

    <feature name="FirebasePlugin">
     <param name="android-package" value="org.apache.cordova.firebase.FirebasePlugin" />
     <param name="onload" value="true" />
</feature>

What does actually happen?

It appears that if onload is set to true, then the plugin instance is started too early before the javascript interface is available, and any callback to the JS interface will fail.

See dpa99c/cordova-plugin-firebasex#888

Could be related to #1605

Environment, Platform, Device

cordova-android 12.0.1 and 13.0.0
cordova 12.0.0 ([email protected])

@breautek
Copy link
Contributor

I do not believe it's related to #1605 which simply makes CoreAndroid (a plugin itself) be loaded via "onload", which is the equivalent of it doing <param name="onload" value="true" /> if it actually had it's own plugin.xml.

CoreAndroid isn't responsible for managing plugins or "starting" any plugins. It's purpose is to provide some core JS apis to handle hardware back button presses, among couple of other niche things. In otherwords, #1605 wouldn't have changed plugin loading behaviour of other plugins which uses onload.

With that being said, I'm not so certain this is a bug with cordova-android either. The onload parameter is to initialise the plugins on platform startup which the PluginManager does so here, invoked by CordovaWebViewImpl.init. This initialization chain starts here.

The init makes and configures the webview and initialises all plugins that has the onload parameter set to true. The loading of the webview app happens later, here. Noting that these parts of the codebase hasn't changed for 10+ years, if you use the blame tool to see when the last changes on those lines occurred.

So for about a decade, onload plugins always were initialised before the webview was fully loaded. Attempting to call JS on plugin initialise while the plugin is initialised onload will likely result in a race condition, depending on how the plugin invokes a JS call.

I acknowledge that the documentation does not detail any of this whatsoever. The android plugin docs has 2 sentences noting the existence of the onload parameter, that's about it. Which is why I took the time to dig through the code base to get an understanding on how plugins gets initialised. If anything this highlights an issue with our documentation, but behaviour wise I do not think this is a bug with cordova-android.

@globules-io
Copy link
Author

globules-io commented May 30, 2024

"Attempting to call JS on plugin initialise while the plugin is initialised onload will likely result in a race condition, depending on how the plugin invokes a JS call."
I guess that answers the question. It definitely causes a race condition. That being said, what is the proper workflow for a plugin with onload to know when its JS interface is ready?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants