Skip to content

InAppBrowser will not destroy WebView after being closed (by invoking ref.close()) causing memory leaks #290

@keithdmoore

Description

@keithdmoore

On both Android and iOS, ref.close() does not close the window. I can see the webview is still running. Does not seem to be specific to device or OS. However, I have been testing on iPhone X, with iOS 11.4.1 as well as Samsung S5 running Android 6.0.1.

Activity

janpio

janpio commented on Aug 31, 2018

@janpio
Member

What happens instead? Does it just stay open?

keithdmoore

keithdmoore commented on Sep 1, 2018

@keithdmoore
Author

Yes. It just stays open.

heidji

heidji commented on Oct 10, 2018

@heidji

+1

before installing inAppBrowser ref.close() would work on Android. Now it doesn't.

janpio

janpio commented on Oct 30, 2018

@janpio
Member

Some context please: What is this ref.close() you refer to? You used this before using inappbrowser @heidji?

heidji

heidji commented on Oct 30, 2018

@heidji
import {InAppBrowser} from "@ionic-native/in-app-browser";
....
let ref = window.open('https://www.example.com/', '_system');
ref.close(); //does nothing

yes, i had to install the plugin because in iOS window.open doesn't work without having InAppBrowser installed, so before the plugin ref.close() in this scenario would work. now it doesn't

heidji

heidji commented on Nov 16, 2018

@heidji

@janpio I am sorry the @ionic-native plugin used in this example could be confusing, i also tested the matter by calling the cordova plugin directly using cordova.InAppBrowser.open and trying to close it also without success, se yeah it's the definitely the plugin's fault.

janpio

janpio commented on Nov 16, 2018

@janpio
Member

Ok, so https://github.com/apache/cordova-plugin-inappbrowser#inappbrowserclose does not actually work but leave the InAppBrowser window that was opened, open?

It would be awesome if one of you both could create a reproduction app with cordova create, implement the minimal code needed to show the problem and put it on GitHub.

heidji

heidji commented on Nov 16, 2018

@heidji

sure, go at it, doesn't work:

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
var app = {
    // Application Constructor
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },

    // deviceready Event Handler
    //
    // Bind any cordova events here. Common events are:
    // 'pause', 'resume', etc.
    onDeviceReady: function() {
        this.receivedEvent('deviceready');
    },

    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);

        setTimeout(() => test(), 3000);
    }


};
test = function () {
    var ref = cordova.InAppBrowser.open('https://www.google.com', '_system');
    setTimeout(() => ref.close(), 3000);
}
app.initialize();
heidji

heidji commented on Nov 16, 2018

@heidji

i also created a rep for you, please forgive me if i added too many files in there, i really have no idea about cordova in particular and it doesn't have a built in gitignore file: replink

janpio

janpio commented on Nov 16, 2018

@janpio
Member

Thanks, the repo is perfect.

While checking it out, I had a look at the documentation. Something popped up at me:

The object returned from a call to cordova.InAppBrowser.open when the target is set to '_blank'.
https://github.com/apache/cordova-plugin-inappbrowser#inappbrowser

Several of the methods mention that they only work with _blank, and the .close example also uses _blank.

This might be the first thing to investigate.

heidji

heidji commented on Nov 16, 2018

@heidji

i also suspected something similar, i think i can live with _blank :D

heidji

heidji commented on Nov 16, 2018

@heidji

@janpio actually the behavior of _blank isn't useful to me, it opens inside the app itself and doesn't close either..
i mean it uses the app as a browser

49 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
InAppBrowser will not destroy WebView after being closed (by invoking ref.close()) causing memory leaks · Issue #290 · apache/cordova-plugin-inappbrowser