Search code examples
angularionic-frameworkinappbrowsersubscribe

I'm having trouble using InAppBrowser browser.onloadstart '). subscribe, with de ionic


**I currently have the following code:

import {InAppBrowser, InAppBrowserOptions, InAppBrowserEvent, InAppBrowserObject} from '@ ionic-native / in-app-browser / ngx';
let options: InAppBrowserOptions = {
       clearcache: 'yes', hidden: 'yes', hidenavigationbuttons: 'yes', hideurlbar: 'yes'
     };
   
    const browser = this.iab.create (url, '_ blank', options);
    browser.show ();
    browser.on ('exit'). subscribe ((ev: InAppBrowserEvent) => {    alert ('closing');
});

I mark the following error**

core.js: 15724 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'subscribe' of undefined
TypeError: Cannot read property 'subscribe' of undefined

Solution

  • Probably an message in your browser is showing you in the console.

    You use Chrome Inspect, and see if you get the following message:

    Native: InAppBrowser is not installed or you are running on a browser. Falling back to window.open, all instance methods will NOT work.

    If so, try executing these 2 commands to add again: inappbrowser plugin and the native one for the mobile:

    > ionic cordova plugin add cordova-plugin-inappbrowser
    > npm install @ionic-native/in-app-browser
    

    Just keep in mind that this is a cordova plugin that will not run on ionic serve, but on ionic cordova run browser. Or try to run the app on a simulator/real device to use the plugin.

    Best regards.