cordova-plugin-inappbrowser
cordova-plugin-inappbrowser copied to clipboard
Opening a _blank window from a _blank window destroys the first window
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