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 plugin installation - ERROR ReferenceError: cordova is not defined #711

Open arafhossain opened 3 years ago

arafhossain commented 3 years ago

Bug Report

Problem

What is expected to happen?

I'm trying to get the InAppBrowser function up and working on my Ionic App. I'm following the steps on the page 'https://github.com/apache/cordova-plugin-inappbrowser.' The only installation step it says to do is run 'cordova plugin add cordova-plugin-inappbrowser.' Then it begins discussing basic operations on starting the inAppBrowser.

My code is

var ref = cordova.InAppBrowser.open('www.google.com', '_blank')

I would expect this to open up the Google website in my Ionic Lab Android platform emulator.

What does actually happen?

Instead, I get the error: 'ERROR ReferenceError: cordova is not defined'. Someone else posted a similar question, and the suggested solution was to add a Script tag: ' ' to their index.html file. That didn't work for me - but I wonder why that was even suggested. I didn't install any other packages/run any other commands besides the 'cordova plugin add cordova-plugin-inappbrowser' stated at the top of the Github docs on the InAppBrowser page. What am I missing?

Information

Command or Code

cordova plugin add cordova-plugin-inappbrowser.
var ref = cordova.InAppBrowser.open('www.google.com', '_blank')

Version information

Ionic:

   Ionic CLI                     : 5.4.16 (/usr/local/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 5.0.7
   @angular-devkit/build-angular : 0.803.26
   @angular-devkit/schematics    : 8.3.26
   @angular/cli                  : 8.3.26
   @ionic/angular-toolkit        : 2.2.0

Capacitor:

   Capacitor CLI   : 2.0.2
   @capacitor/core : 2.0.2

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : android 8.1.0, ios 5.1.1
   Cordova Plugins   : cordova-plugin-device 2.0.2 "Device"
     cordova-plugin-inappbrowser 3.2.0 "InAppBrowser"
     cordova-plugin-ionic-keyboard 2.2.0 "cordova-plugin-ionic-keyboard"
     cordova-plugin-ionic-webview 4.2.1 "cordova-plugin-ionic-webview"
     cordova-plugin-splashscreen 5.0.2 "Splashscreen"
     cordova-plugin-statusbar 2.4.2 "StatusBar"
     cordova-plugin-whitelist 1.3.3 "Whitelist"

Utility:

   cordova-res : not installed
   native-run  : 1.0.0

System:

   ios-sim : 8.0.2
   NodeJS  : v12.16.1 (/usr/local/bin/node)
   npm     : 6.14.3
   OS      : macOS Catalina
   Xcode   : Xcode 11.3.1 Build version 11C504

Checklist

breautek commented 3 years ago

Are you waiting for the deviceready event before executing cordova.InAppBrowser.open('www.google.com', '_blank')?

Documentation could be improved imo, but it does mention it at https://github.com/apache/cordova-plugin-inappbrowser#installation ... just seems to be in odd ordering.

arafhossain commented 3 years ago

Thanks for mentioning that @breautek, it's certainly something I didn't consider was necessary - but although now I have no errors, simply nothing happens. My updated ineffective code:

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady(){
  console.log('Called on device ready!')
  var ref = cordova.InAppBrowser.open('www.google.com', '_self')
} 

A step forward, not there yet.

ericgopak commented 3 years ago

Have you tried adding a scheme to the URL? For example,

https://www.google.com

instead of just

www.google.com
faisal-easi commented 3 years ago

i'm facing this same issue

jerimiahmilton commented 9 months ago

My issue seems to disappear when removing cordova. when calling the InAppBrowser plugin. var ref = InAppBrowser.open('https://www.google.com', '_self');

shabbir-hossain-ftdl commented 2 months ago

Thanks for mentioning that @breautek, it's certainly something I didn't consider was necessary - but although now I have no errors, simply nothing happens. My updated ineffective code:

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady(){
  console.log('Called on device ready!')
  var ref = cordova.InAppBrowser.open('www.google.com', '_self')
} 

A step forward, not there yet.

Did you find any solution to this issue after that @arafhossain?