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

Opening a _blank window from a _blank window destroys the first window #965

Open
3 tasks done
lifeontime opened this issue Jul 19, 2022 · 0 comments
Open
3 tasks done

Comments

@lifeontime
Copy link

lifeontime commented Jul 19, 2022

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

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
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