Here's code I added to a blank
Angular+Capacitor starter project produced by Ionic's CLI (within home.page.ts
):
openInAppBrowser() {
const exampleUrl = 'https://ionicframework.com/docs/components';
const options: InAppBrowserOptions = {
usewkwebview: 'yes'
};
const browser = this.iab.create(exampleUrl, '_blank', options);
const eventTypes: InAppBrowserEventType[] = ['loadstart', 'loadstop', 'beforeload', 'exit', 'loaderror'];
eventTypes.forEach(eventType => {
browser.on(eventType).subscribe(event => {
console.log(`Event ${eventType} fired!`); // Doesn't get here
console.log(`URL: [${event.url}]`); // or here (obviously).
if (event.url && event.url.includes('path-i-am-interested-in')) {
// Do useful stuff...
}
});
});
console.log(`Browser object after subscription:`);
console.log(browser);
}
When I deploy this to an iPhone 11 simulator or tethered to my iPhone 11 through XCode, none of the console.log
calls fire within the listener.
I built an Ionic-Vue project with this code, and it works fine. Why doesn't this work with Angular?
Here's the pared-down repo with the full implementation:
https://bitbucket.org/aaronw322/ionic-inappbrowser-subscription/src/master/
The README outlines the steps I took to install/build it.
Here are the logs from XCode's console after opening the InAppBrowser example site, clicking links, then pressing Done
in the bottom corner of the InAppBrowser window (notice that none of the desired log output is shown):
To Native Cordova -> InAppBrowser open InAppBrowser694511092 ["options": [https://ionicframework.com/docs/components, _blank, usewkwebview=yes]]
2020-11-07 09:26:23.859892-0500 App[22260:325714] WF: _userSettingsForUser : (null)
2020-11-07 09:26:23.860064-0500 App[22260:325714] WF: _WebFilterIsActive returning: NO
⚡️ [log] - Browser object after subscription:
⚡️ [log] - {"_objectInstance":{"channels":{"beforeload":{"type":"beforeload","handlers":{},"state":0,"fireArgs":null,"numHandlers":1,"onHasSubscribersChange":null},"loadstart":{"type":"loadstart","handlers":{},"state":0,"fireArgs":null,"numHandlers":1,"onHasSubscribersChange":null},"loadstop":{"type":"loadstop","handlers":{},"state":0,"fireArgs":null,"numHandlers":1,"onHasSubscribersChange":null},"loaderror":{"type":"loaderror","handlers":{},"state":0,"fireArgs":null,"numHandlers":1,"onHasSubscribersChange":null},"exit":{"type":"exit","handlers":{},"state":0,"fireArgs":null,"numHandlers":1,"onHasSubscribersChange":null},"customscheme":{"type":"customscheme","handlers":{},"state":0,"fireArgs":null,"numHandlers":0,"onHasSubscribersChange":null},"message":{"type":"message","handlers":{},"state":0,"fireArgs":null,"numHandlers":0,"onHasSubscribersChange":null}}}}
⚡️ [log] - onscript loading complete
⚡️ WebView loaded
2020-11-07 09:26:24.078843-0500 App[22260:325714] No
2020-11-07 09:26:24.090239-0500 App[22260:325714] didStartProvisionalNavigation
⚡️ [log] - Angular is running in development mode. Call enableProdMode() to enable production mode.
⚡️ [log] - Ionic Native: deviceready event fired after 91 ms
⚡️ [warn] - Native: tried calling StatusBar.styleDefault, but the StatusBar plugin is not installed.
⚡️ [warn] - Install the StatusBar plugin: 'ionic cordova plugin add cordova-plugin-statusbar'
⚡️ [warn] - Native: tried calling SplashScreen.hide, but the SplashScreen plugin is not installed.
⚡️ [warn] - Install the SplashScreen plugin: 'ionic cordova plugin add cordova-plugin-splashscreen'
2020-11-07 09:26:24.427205-0500 App[22260:325714] Unbalanced calls to begin/end appearance transitions for <UIViewController: 0x7fa6c450df80>.
⚡️ To Native -> App addListener 86862752
2020-11-07 09:41:26.240739-0500 App[22260:325714] [assertion] Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=3 "Target is not running or required target entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"Background" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Target is not running or required target entitlement is missing}>
2020-11-07 09:41:26.240903-0500 App[22260:325714] [ProcessSuspension] 0x10cc0ff00 - ProcessAssertion: Failed to acquire RBS Background assertion 'WebProcess Background Assertion' for process with PID 22267, error: Error Domain=RBSAssertionErrorDomain Code=3 "Target is not running or required target entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"Background" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Target is not running or required target entitlement is missing}