apache / apache/cordova-plugin-inappbrowser

'beforeload' event can only fire once in an InAppBrowser session

Open
#571 11 comments 1 reaction 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
When an InAppBrowser session is started, the 'beforeload' event will only ever trigger once.
### What is expected to happen?
Every time a redirect event is triggered from the InAppBrowser, 'beforeload' should trigger and run each time.
### What does actually happen?
If the InAppBrowser session is not killed as a result of the 'beforeload' event, all attempts at redirect from that moment on do nothing. All URLs essentially break.
## Information

I have a SPA that gets accessed as part of my Cordova application. There are some URLs within that SPA that cannot be handled by Cordova's InAppBrowser (at least on Android) in any capacity. Any URL that does not use the HTTP protocol (for example, deep link URLs that use a different protocol) fail. As a result, I wanted to hook into the 'beforeload' event for two reasons:

1. I can intercept this request to the URL the InAppBrowser cannot handle and redirect the user to that page using the system browser.
2. I can prevent the user's SPA session from being killed off and having to be refreshed.

Using the 'beforeload' event accomplishes both items. My InAppBrowser session switches to the System Browser, and if I back out of the System Browser or return to the application, the page stays where it was in the state it was in. However, from that moment on, every single link fails to work. I can no longer navigate in any capacity to any other URL. This makes the 'beforeload' event completely useless to me, because I need to be able to navigate to other locations.

### Command or Code

`
inAppObj.addEventListener('beforeload', (event: any, callback: Function) => {
let currentURL: string = event.url;
if (currentURL.includes('someurl')) {
cordova.InAppBrowser.open(currentURL, '_system');
}
else {
callback(currentURL);
}
});
`

### Environment, Platform, Device

This is specifically an issue that I've noticed on Android, as I am trying to fix an issue specific to Android.

### Version information
` "cordova": "9.0.0",
"cordova-android": "8.1.0",
"cordova-ios": "5.0.0",
"cordova-browser": "6.0.0",
"cordova-plugin-androidx": "1.0.2",
"cordova-plugin-androidx-adapter": "1.1.0",
"cordova-plugin-device": "2.0.3",
"cordova-plugin-firebasex": "6.1.0",
"cordova-plugin-inappbrowser": "3.1.0",
"cordova-plugin-local-notification": "0.9.0-beta.2",
"cordova-plugin-network-information": "2.0.2",
"cordova-plugin-secure-storage": "3.0.2",
"cordova-plugin-whitelist": "1.3.4"`

## Checklist

- [x] I searched for existing GitHub issues
- [x] 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 the Android InAppBrowser implementation and the beforeload addEventListener entry point, then reproduce the supplied listener with cordova-plugin-inappbrowser 3.1.0. Trace navigation after the first intercepted redirect; done means each subsequent redirect emits beforeload and remains navigable, with no source file or test named in the report.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java, javascript
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.