-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
InAppBrowser will not destroy WebView after being closed (by invoking ref.close()) causing memory leaks #290
InAppBrowser will not destroy WebView after being closed (by invoking ref.close()) causing memory leaks #290
Comments
What happens instead? Does it just stay open? |
Yes. It just stays open. |
+1 before installing inAppBrowser ref.close() would work on Android. Now it doesn't. |
Some context please: What is this |
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 |
@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. |
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 |
sure, go at it, doesn't work:
|
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 |
Thanks, the repo is perfect. While checking it out, I had a look at the documentation. Something popped up at me:
Several of the methods mention that they only work with This might be the first thing to investigate. |
i also suspected something similar, i think i can live with _blank :D |
@janpio actually the behavior of _blank isn't useful to me, it opens inside the app itself and doesn't close either.. |
I can reproduce the behaviour you describe in the unchanged app. After adding some debugging and changing to |
actually i was mistaken about _blank not closing, but it's because also in my app _blank doesn't work: the reason being that the external http location having a callback with myapp:// scheme to return to the app, but in _blank this call never gets through. yes your rep works, but _blank doesn't work for me, it has to be an external browser with _system in order to call the custom URL scheme. |
@keithdmoore Did you original issue also refer to IAB using The next step to debug this would be to see what happens on the native side of things - cordova-plugin-inappbrowser/src/android/InAppBrowser.java Lines 509 to 543 in 3eadde6
Unfortunately I am not set up for this. @heidji I understand this doesn't match your usecase - maybe open a new issue describing it again and asking for solutions (I might have an idea). |
@janpio okay thanks, will open an issue for my use case |
@janpio I am using ‘_blank’ and the close method leaves the inappbrowser running. It’s hidden but it’s still running. Having these running will cause memory issues |
Ok, so you actually have a different "problem" than @heidji had - good that we moved his to new issues. I updated the title of this issue - is this correct? How did you discover that the webview is still running exactly? Update: I could reproduce what you describe in Android and the Chrome dev tools: |
@janpio that’s pretty close to what I was seeing. It’s been awhile since I looked into this issue |
Any workaround for this? |
Interestingly, on Android 8 (Webview 72.0.3626.121) I see a similar build up of _blank windows until I get to between 5 and 7. Then suddenly most of the dead windows seem go get garbage collected. I'll check iOS 12... I cannot now reproduce the original problem on iOS 12, and there is no build up of dead _blank windows, at least this is not visible via the Safari Develop menu. The only thing I changed was to move the iab reference up and make it an object field rather than a local variable. I will continue testing and see if it happens again on iOS. After more testing on iOS 12 there seems to be a causal relationship between html5 video and IAB. My app plays an internal video on the welcome screen. This is configured to play inline but sometimes it goes fullscreen when I press play. After I close the fullscreen video and open IAB I sometimes get the a blank white window. Sometimes closing the fullscreen video crashes the app, and when this happens IAB is always blank after I restart the app. I then have to reinstall the app (not tried rebooting) to reset things. I am now experimenting with using Video.js to see if this stops my app crashing when I play video and also cures this IAB issue. |
@keithdmoore et al. The problem is reappearing again on iOS. I thought it was related to running html5 video in the app (not in the IAB window - in the main webview) because html5 video was causing my app to crash when closing fullscreen mode. I can reliably reproduce this IAB problem on iOS 12 by opening a video in fullscreen and closing it three or four times until the app crashes. After starting the app again all IAB windows (which I am using for displaying internal documentation) are white and I start seeing a build up of ghost windows in the Safari Develop sub menu for the device. Interestingly, the forward and back controls in the bottom bar (RHS) of the IAB window go from grey to blue but do not respond to clicks. This behaviour continues until either the app is reinstalled or the device is rebooted. Given that html5 video is unusable in my Cordova app I have removed all video. After doing this I continued testing the app and again found that the IAB windows started displaying no content, just a white empty screen with nothing in the document and no error messages. Not sure what caused this. I was connected to the app with Safari in order to debug, and I was messing with css issues editing CSS live in the Safari debugger. Beyond this I was just navigating between pages in the app (using Bootstrap Carousel for now). I am now going to stop using IAB, uninstall it and code an alternative for displaying my internal docs as I need to release asap and cannot afford to send it out misbehaving like this on iOS. I don't know what else to do as this issue is beyond my current abilities to debug. |
I made this change in the closeDialog function and it worked for me, I also recommend waiting about three seconds after calling the close function before calling the function to open again.
|
Above worked for me |
Is there any update to this? I've tested the code that @HarshRohila posted, and it worked without a problem in my cordova app. |
any fix for iOS? |
By analyzing the native code for IOS (of version 3.2) I found that the close event is only triggered while the browser is in the process of being hidden. If the browser is already hidden - for example through the options property - the close call method will not be called. Thus a quick fix for IOS was for me to call show() just before closing the browser:
|
This solution seems to work even though it's not that nice for the user to see even for a second the browser opening and closing.. Any better option? it's quite annoying |
…using memory leak (bug apache#290)
Whenever closing an InAppBrowser instance, a webview was left in memory with about:blank page. This change fixes the issue by destroying and freeing the inAppWebView object.
It's 2022 and same thing still happens to me on Android. Jeez, cordova is such a dead thing. Literally every plugin is outdated by at least 2 or 3 years and not maintained, with 15 forks floating around the internet but nobody even cares to accept the pull requests. |
…ty (#42) * Fix memory leak - initially reported in apache#290 Whenever closing an InAppBrowser instance, a webview was left in memory with about:blank page. This change fixes the issue by destroying and freeing the inAppWebView object. * Fix beforeLoad not being called in some requests - initially reported in apache#686 The waitForBeforeload flag was preventing beforeLoad from being called on every GET request. * Do not lose callbackContext when opening a SYSTEM url This fixes a condition where it was not possible to open a SYSTEM url while an InAppBrowser instance is displayed. The callbackContext of the InAppBrowser instance was lost when the SYSTEM url was opened. This fixes the issue by not setting the callbackContext on SYSTEM urls. * Fix crash when pausing/resuming application after closing InAppBrowser * Fix _loadAfterBeforeload callback not working due to this.rootName not being defined. * Reset beforeload variable if a new instance of InAppBrowser is opened without beforeload setting * chore: update changelog References: https://outsystemsrd.atlassian.net/browse/RMET-2802 * refactor: remove empty lines * refactor: use ternary operator and remove unnecessary ones Why: We can refactor the if-else block that assigns a value to beforeload to use a ternary operator. On the other hand, we can remove the unnecessary ternary operators used to assign a boolean value. They are redundant. References: https://outsystemsrd.atlassian.net/browse/RMET-2802 --------- Co-authored-by: Leonardo Monteiro Fernandes <[email protected]> Co-authored-by: Nelson Lopes Silva <[email protected]>
Fix for webView window not being destroyed correctly causing memory leak (apache/cordova-plugin-inappbrowser#290)
* RMET-2119 InAppBrowser Plugin - Check for element before obtaining it (#40) * fix: check if there's a next token before trying to obtain it References: https://outsystemsrd.atlassian.net/browse/RMET-2119 * chore: update changelog * RMET-2802 InAppBrowser Plugin - Multiple minor fixes from the community (#42) * Fix memory leak - initially reported in apache#290 Whenever closing an InAppBrowser instance, a webview was left in memory with about:blank page. This change fixes the issue by destroying and freeing the inAppWebView object. * Fix beforeLoad not being called in some requests - initially reported in apache#686 The waitForBeforeload flag was preventing beforeLoad from being called on every GET request. * Do not lose callbackContext when opening a SYSTEM url This fixes a condition where it was not possible to open a SYSTEM url while an InAppBrowser instance is displayed. The callbackContext of the InAppBrowser instance was lost when the SYSTEM url was opened. This fixes the issue by not setting the callbackContext on SYSTEM urls. * Fix crash when pausing/resuming application after closing InAppBrowser * Fix _loadAfterBeforeload callback not working due to this.rootName not being defined. * Reset beforeload variable if a new instance of InAppBrowser is opened without beforeload setting * chore: update changelog References: https://outsystemsrd.atlassian.net/browse/RMET-2802 * refactor: remove empty lines * refactor: use ternary operator and remove unnecessary ones Why: We can refactor the if-else block that assigns a value to beforeload to use a ternary operator. On the other hand, we can remove the unnecessary ternary operators used to assign a boolean value. They are redundant. References: https://outsystemsrd.atlassian.net/browse/RMET-2802 --------- Co-authored-by: Leonardo Monteiro Fernandes <[email protected]> Co-authored-by: Nelson Lopes Silva <[email protected]> --------- Co-authored-by: Leonardo Monteiro Fernandes <[email protected]> Co-authored-by: Nelson Lopes Silva <[email protected]>
This did the trick for me for iOS: Something-Useful@61720c6 |
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.
The text was updated successfully, but these errors were encountered: