apache / apache/cordova-plugin-inappbrowser
Opening a _blank window from a _blank window destroys the first window
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 2.2k
- PR merge metrics
- No merged PRs in 30d
Description
# Bug Report
## Problem
I use an IAB instance to load my site into a Cordova webview in a _blank window so I can catch calls to window.open and replace them with cordova.InAppBrowser.open. This works fine the first time, however when the new window loads (also _blank) the first IAB instance seemingly gets destroyed (after inspecting, it is actually set to about:blank).
### What is expected to happen?
The first IAB instance should load the second and still exist when the second instance is closed.
### What does actually happen?
The first IAB instance loads the second but seemingly gets destroyed in the process.
## Information
### Command or Code
```
document.addEventListener('deviceready', function() {
var url = 'https://example.com/login/';
newWindowRef = cordova.InAppBrowser.open( url, '_blank', 'location=no,toolbar=no' );
listenForMessage( newWindowRef );
newWindowRef.addEventListener( 'loadstop', assignWindowOpenFunction );
}, false);
function assignWindowOpenFunction() {
newWindowRef.executeScript({
code: "\
function openWinFromApp( url, target, options ) {\
var obj = {\
url: url,\
target: target,\
options: options\
};\
var objStr = JSON.stringify(obj);\
webkit.messageHandlers.cordova_iab.postMessage(objStr);\
}\
window.open = openWinFromApp;"
},
function( result ) {
}
);
}
function listenForMessage( win ) {
win.addEventListener( 'message', function( params ) {
var newWin = cordova.InAppBrowser.open( params.data.url, '_blank', 'toolbar=yes,location=yes' );
listenForMessage( newWin );
} );
}
```
### Environment, Platform, Device
OS = Windows 10, Platform = Android (testing on Samsung Galaxy A12)
### Version information
Cordova CLI v 11.0.0, IAB 5
## 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
Research direction
The entry points shown are cordova.InAppBrowser.open, loadstop, executeScript, and the message listener on Android. Reproduce nested _blank opens on the stated Cordova/Android setup, then inspect the InAppBrowser lifecycle around the first window’s navigation to about:blank. Done means the first IAB remains available after the second closes, with the reported flow still working.
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