Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS wrong event.url in IAB events (beforeload, loadstart and loadstop) #780

Open
2 of 3 tasks
guycalledseven opened this issue Sep 11, 2020 · 1 comment
Open
2 of 3 tasks

Comments

@guycalledseven
Copy link

guycalledseven commented Sep 11, 2020

Bug Report

Problem

I have ionic/cordova IOS/Android/Electron project that downloads zip, unzips it and shows html/css/js from that zip.
It worked OK while on UIWebView and cordova-plugin-inappbrowser v3.2.0, but migrating to WKWebView and latest inappbrowser (4.0 from github master branch) proved a bit harder than I expected.

After PR #693 and my PR #778 I managed to open local files using file:// in v4 branch, but XHR did not work.
I decided to ditch local files opening with file:// and I implemented local httpd server (using my fork of cordova-httpd), and managed to get XHR to work again BUT found different and very strange bug.

My app relies on using IAB beforeload, loadstart and loadstop events which handle detection if outbond links were pressed in local html files etc. When page opens, and event gets triggered I can check event.url and see on which url the event got triggered.

What does actually happen?

While using latest version of cordova-plugin-inappbrowser url in event.url comes wrong.

Instead of http://127.0.0.1:8888/20612/21018.html I get http://localhost:8080/127.0.0.1:8888/20612/21018.html.

Notice the extra string: localhost:8080/.

Information

Let's say that my local data is downloaded into
/Users/{username}/Library/Developer/CoreSimulator/Devices/B0B80D63-64FD-4FBD-879B-92D2204BA713/data/Containers/Data/Application/1625CAAA-AF07-4706-BDA2-DB2D85938AB8/Documents/WebRoot, and that is a web root of local webserver.

So the final file I am about to load is located locally in /Users/{username}/Library/Developer/CoreSimulator/Devices/B0B80D63-64FD-4FBD-879B-92D2204BA713/data/Containers/Data/Application/1625CAAA-AF07-4706-BDA2-DB2D85938AB8/Documents/WebRoot/20612/21018.html

Local web server is started on http://127.0.0.1:8888/

The url passed to IAB for opening is http:/127.0.0.1:8888/20612/21018.html

This works ok, page gets opened. However, when ANY event is triggered, the event.url returned is: http://localhost:8080/127.0.0.1:8888/20612/21018.html

I have 0 (zero) references to localhost:8080 in my code or config.xml.
However, I have found out that after preparing project, this gets generated:

  1. in platforms/ios/<APPNAME>/config.xml:
    <allow-navigation href="http://localhost:8080/*" />
    <allow-navigation href="http://127.0.0.1:8080/*" />
  1. and in platforms/ios/ios.json:
...
            {
              "xml": "<allow-navigation href=\"http://localhost:8080/*\" />",
              "count": 1
            },
            {
              "xml": "<allow-navigation href=\"http://127.0.0.1:8080/*\" />",
              "count": 1
            },
...

All in all - allow-navigation configuration shouldn't have ANY impact on event.url.

Command or Code

windowOptions : InAppBrowserOptions | string = {
	location : 'no',
	hidden : 'no', 
	zoom : 'yes',
	useWideViewPort: 'yes',
	hardwareback : 'yes',
	hidenavigationbuttons : 'yes',
	hideurlbar : 'yes',
	mediaPlaybackRequiresUserAction : 'no',
	shouldPauseOnSuspend : 'yes',
	closebuttoncaption : this.translate.instant('book.close'),
	disallowoverscroll : 'no',
	toolbar : 'no',
	toolbartranslucent : 'yes',
	enableViewportScale : 'yes',
	allowInlineMediaPlayback : 'yes',
	presentationstyle : 'fullscreen',
	fullscreen : 'yes',
    footer: 'no',
    beforeload: 'get'
};

var url = "http:/127.0.0.1:8888/20612/21018.html";
this.windowOptions = this.toOptionsString(this.windowOptions);
var browserIab = cordova.InAppBrowser.open(url, '_blank', this.windowOptions);

browserIab.addEventListener('beforeload', (event, load) => {
        if (this.isUrlHomePage(event.url))
        {
            browserIab.close();
            return;
        }
});

private toOptionsString(optionsObject) {
    return Object.keys(optionsObject).map((key) => key + '=' + optionsObject[key]).join(',');
}

Environment, Platform, Device

iOS 13.7

Version information

Ionic:

   Ionic CLI          : 6.11.8 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework    : ionic-angular 3.9.4
   @ionic/app-scripts : 3.2.3

Cordova:

   Cordova CLI       : 10.0.0
   Cordova Platforms : ios 5.1.1
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 2.5.3, cordova-plugin-ionic 5.4.7, (and 20 other plugins)

Utility:

   cordova-res : 0.15.1
   native-run  : 1.0.0

System:

   ios-sim : 8.0.2
   NodeJS  : v12.18.3 (/usr/local/Cellar/node@12/12.18.3/bin/node)
   npm     : 6.14.8
   OS      : macOS Catalina
   Xcode   : Xcode 11.7 Build version 11E801a

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@guycalledseven guycalledseven changed the title iOS wrong event.url in IAB events (beforeload, loadstart and loadstop) iOS wrong event.url in IAB events (beforeload, loadstart and loadstop) when loading local files Sep 11, 2020
@guycalledseven guycalledseven changed the title iOS wrong event.url in IAB events (beforeload, loadstart and loadstop) when loading local files iOS wrong event.url in IAB events (beforeload, loadstart and loadstop) Sep 11, 2020
@guycalledseven
Copy link
Author

UPDATE:
At first I thought this was because cordova-ios version 5.1.1 is old, but I updated to 6.1.1 of cordova-ios with the same strange result.

After further testing, I was able to pinpoint this issue to cordova-plugin-ionic-webview.

I was using pretty old version 2.5.3. When I updated to latest 5.0 event.url was ok (without localhost:8080/), did not break anything in the process.

2020-09-11 15:33:32.223709+0200 IZZI[7618:2744419]  beforeload event_url: http://127.0.0.1:8888/20612/21018.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant