apache / apache/cordova-plugin-inappbrowser

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

Open
#780 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.1k
Forks
2.2k
PR merge metrics
No merged PRs in 30d

Description

# 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](https://github.com/guycalledseven/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//config.xml`:

```


```

2. and in `platforms/ios/ios.json`:
```
...
{
"xml": "",
"count": 1
},
{
"xml": "",
"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

- [X] I searched for existing GitHub issues
- [ ] I updated all Cordova tooling to most recent version
- [X] I included all the necessary information above

Contributor guide

Open the contributing guide

Research direction

Start at cordova.InAppBrowser.open and the beforeload, loadstart, and loadstop event paths described in the report. Compare event.url with the supplied local-server URL, using the generated platforms/ios//config.xml and platforms/ios/ios.json as configuration evidence. Reproduce on iOS 13.7 with the shown options; done means these events report the opened URL without the unexpected localhost:8080 prefix.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, javascript
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.