cordova-plugin-inappbrowser icon indicating copy to clipboard operation
cordova-plugin-inappbrowser copied to clipboard

InAppBrowser Is Undefined During App Runtime

Open anthonygacek opened this issue 4 years ago • 8 comments

Bug Report

InAppBrowser Is Undefined During App Runtime

Problem

Attempting to call the InAppBrowser.open() method results in a TypeError: Cannot read property 'open' of undefined. No recent code changes to this code segment have occurred (it worked as expected on earlier builds), and the call is wrapped inside a platform.ready() call.

What is expected to happen?

The InAppBrowser.open() call should open an in app browser, prompting the user to log in.

What does actually happen?

The InAppBrowser is undefined during execution, resulting in a TypeError that causes an indefinite spinner wheel on the start page of the application.

Information

This was encountered upon switching from Nevercode to Codemagic and attempting to run a new build in Codemagic. The underlying code segment that is now throwing a TypeError has not changed.

Command or Code

window.cordova.InAppBrowser.open( ... )

Environment, Platform, Device

We are experiencing this issue on Android platform version 8.0.0, using an Android device.

Version information

Cordova version 9.0.0, Android platform version 8.0.0, and Node version 10.0.0.

Checklist

  • [ x ] I searched for existing GitHub issues
  • [ ] I updated all Cordova tooling to most recent version
  • [ x ] I included all the necessary information above

anthonygacek avatar Feb 12 '21 23:02 anthonygacek

and the call is wrapped inside a platform.ready() call.

Does this call waits for the deviceready event that gets fired on the document?

What version of this plugin are you using? (cordova plugin ls should tell you)

breautek avatar Feb 13 '21 00:02 breautek

According to the platform.ready() call: Returns a promise when the platform is ready and native functionality can be called. If the app is running from within a web browser, then the promise will resolve when the DOM is ready. When the app is running from an application engine such as Cordova, then the promise will resolve when Cordova triggers the deviceready event. Given that this error occurs when an .apk build of the project is launched on an Android device, I am under the impression this call is waiting for the deviceready event.

I am using version 5.0.1-dev of the InAppBrowser plugin.

anthonygacek avatar Feb 15 '21 15:02 anthonygacek

As a follow-up to the previous post, I added a console.log('Platform ready from', readySource); call within the platform.ready() block to verify that the application is running from the correct engine. This call returns a value of "cordova," thus verifying this is behaving as inspected.

anthonygacek avatar Feb 15 '21 15:02 anthonygacek

I'm unable to reproduce this on cordova@10 cli & cordova-android@9, testing [email protected] (from git master).

Things to try:

  • Upgrading to cordova-android@9
  • Upgrading Cordova CLI to cordova@10

Cordova doesn't support older versions, so if the issue only exists when using older versions they won't be addressed.

If the issue still persists, then we will need to see if the issue persists when isolated from any frameworks you use. The best way to do this is by creating a small reproduction app that contains only what is necessary to reproduce the issue.

If the issue cannot be demonstrated in an isolated environment, then this suggest you a plugin or some framework that is altering how Cordova behaves and a bug should be reported to the respective framework/plugin authors.

Please do let me know your outcome.

breautek avatar Feb 16 '21 16:02 breautek

Cordova as update from the oficial plugin. https://cordova.apache.org/announcements/2021/02/16/inappbrowser-release-5.0.0.html

jorhel avatar Feb 24 '21 15:02 jorhel

I solved it by moving <script src="cordova.js"></script> to <head> instead of 'body'.

pjc0247 avatar May 21 '21 03:05 pjc0247

Make sure that your config.xml contains the plugin info plugin name="cordova-plugin-inappbrowser" spec="version"

png995 avatar Nov 26 '21 09:11 png995

Make sure that your config.xml contains the plugin info plugin name="cordova-plugin-inappbrowser" spec="version"

This save my problem

qiutian00 avatar Apr 26 '24 05:04 qiutian00