apache / cordova-plugin-inappbrowser

Apache Cordova InAppBrowser Plugin
https://cordova.apache.org/
Apache License 2.0
1.11k stars 2.14k forks source link

InAppBrowser Is Undefined During App Runtime #848

Open anthonygacek opened 3 years ago

anthonygacek commented 3 years ago

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

breautek commented 3 years ago

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)

anthonygacek commented 3 years ago

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 commented 3 years ago

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.

breautek commented 3 years ago

I'm unable to reproduce this on cordova@10 cli & cordova-android@9, testing cordova-plugin-inappbrowser@5.0.1-dev (from git master).

Things to try:

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.

jorhel commented 3 years ago

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

pjc0247 commented 3 years ago

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

png995 commented 2 years ago

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

qiutian00 commented 2 months ago

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

This save my problem