Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
4.0.0
-
None
-
None
-
iphone 5, ios9.1
Description
Occasionally the entire web view is cleared. White screen. Plugins and other components remain unaffected. Observed when playing background audio (via CDVSound), going to background, and running other apps. Audio continues uninterrupted, but bringing the app to foreground reveals white screen.
It appears to be related to an issue with the XPC connection being lost between the app and the wkwebview (log in XCode mentioned the XPC connection being interrupted). (see also: http://stackoverflow.com/questions/25854143/wkwebview-intermittent-blank-screen-issue )
The plugin should detect if the WKWebView has reset and reload the app.
Attachments
Issue Links
- breaks
-
CB-11554 too "brutal" app reload when title is empty
- Closed
- links to
Activity
Ouch. I'm wondering if any delegate function gets triggered when this happens, perhaps that is a better crash detection.
i'm suffering from this - one of the comments on the telerik plugin issue
https://github.com/Telerik-Verified-Plugins/WKWebView/issues/41#issuecomment-172696256
indicates that
(void)webViewWebContentProcessDidTerminate:(WKWebView *)webView
gets triggered - i have not verified this is the case - i have not been able to catch the problem in an xcode session yet
so the `webViewContentProcessDidTerminate` delegate function on `CDVWKWebViewEngine` already does something sensible, i.e. `[wkWebView reload]` ... i was still suffering from occasional White Screen Of Death though, unpredictably but invariably after some hours of the app being in the background and therefore pretty much impossible to catch in a debugger
making the assumption that the problem was that in some cases the `webViewContentProcessDidTerminate` delegate function doesn't get called when an app is resumed i implemented the following :
https://github.com/employeerepublic/cordova-ios/commits/4.1.1-branch
https://github.com/employeerepublic/cordova-plugin-wkwebview-engine/commits/1.0.3-branch
which adds a `- (BOOL)reloadIfRequired` method to `CDVWebViewEngineProtocol` and calls it from `CDVViewController.onAppWillEnterForeground`. in the `CDVWKWebViewEngine` the implementation uses the title tag hack outlined above to determine if the content process is alive, and if not does the `[wkWebView reload]`
none of our users have had a WSOD incident since i implemented this patch 4 days ago, though given the nature of the problem "absence of evidence is not evidence of absence", but i would have expected a couple of incidences in that time prior to my patch
I'm hesitant to add new API when an alternative can exist.
I would prefer to do instead:
1. cordova-plugin-wkwebview-engine listens for the UIApplicationWillEnterForegroundNotification notification
2. if it gets the notification, it will determine whether it should reload itself
Example in CDVWKWebViewEngine.m:
// this is in the pluginInitialize [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil]; - (void) onAppWillEnterForeground:(NSNotification*)notification { // put your logic to determine whether to reload here }
What do you think?
your approach is much better
i'll update my CDVWKWebViewEngine patch
Great! If you want to send a pull request, that will be great as well
will do
one thing i forgot though - the original approach i took avoided sending the js "resume" event when the app gets reloaded (based on the BOOL return from the additional `reloadIfRequired` method), since it's effectively a restart
an observer of UIApplicationWillEnterForegroundNotification would not be able to do that - will that be a problem, or will the js "resume" disappear into the void since the WkWebView has no live content process ?
Shouldn't be a problem – but let's try that hypothesis with the new patch
cool, just got confirmation that this reload technique based on title tag is helping... from my phone logs as my app resumes
in this first trace the app came back with a white-screen, the WKWebView title was empty and the app reloaded - recovery !
Jun 9 20:07:03 gluupi YapDev[1940] <Warning>: CDVWKWebViewEngine reloadIfRequired Jun 9 20:07:03 gluupi YapDev[1940] <Warning>: CDVWKWebViewEngine reloadIfRequired WKWebView.title: Jun 9 20:07:03 gluupi YapDev[1940] <Warning>: CDVWKWebViewEngine reloadIfRequired reload: 1 Jun 9 20:07:03 gluupi kernel[0] <Notice>: Sandbox: YapDev(1940) deny(1) file-issue-extension / Jun 9 20:07:03 gluupi YapDev[1940] <Warning>: IAB.close() called but it was already closed. Jun 9 20:07:06 gluupi YapDev[1940] <Warning>: THREAD WARNING: ['PushNotification'] took '49.469971' ms. Plugin should use a background thread. Jun 9 20:07:06 gluupi YapDev[1940] <Warning>: INFO: INFO [er-webui.platform.init:23] - initialise - platform: iOS
this trace is a normal resume, and the WKWebView still has its title
Jun 9 20:07:23 gluupi YapDev[1940] <Warning>: CDVWKWebViewEngine reloadIfRequired Jun 9 20:07:23 gluupi YapDev[1940] <Warning>: CDVWKWebViewEngine reloadIfRequired WKWebView.title: Yapster Jun 9 20:07:23 gluupi YapDev[1940] <Warning>: CDVWKWebViewEngine reloadIfRequired reload: 0 Jun 9 20:07:23 gluupi YapDev[1940] <Warning>: INFO: INFO [er-webui.platform.resume:22] - cordova event: resume
Planning a plugin release soon, so if we can get a patch out, that will be great.
GitHub user mccraigmccraig opened a pull request:
https://github.com/apache/cordova-plugin-wkwebview-engine/pull/11
CB-9888: (iOS) check & reload WKWebView
PR as discussed on JIRA @shazron
-
-
- Platforms affected
-
iOS 9
-
-
- What does this PR do?
-
Checks whether the WKWebView content process has died when the app enters
the foreground. If it has, then reloads the WKWebView
-
-
- What testing has been done on this change?
-
Tested on iOS9.3 emulator and iPhone 6 / 9.3.1
-
-
- Checklist
-
- [x] [ICLA](http://www.apache.org/licenses/icla.txt) has been signed and submitted to secretary@apache.org.
- [x] [Reported an issue](http://cordova.apache.org/contribute/issues.html) in the JIRA database
- [x] Commit message follows the format: "CB-3232: (android) Fix bug with resolving file paths", where CB-xxxx is the JIRA ID & "android" is the platform affected.
- [x] Added automated test coverage as appropriate for this change.
When an app is entering the foreground,
the WKWebView content process sometimes dies without
calling the webViewContentProcessDidTerminate delegate function.
This PR checks whether the content process has died, by
examining the title property of the WKWebView, which is nil
when the process has died.
If the process has died the WKWebView is reloaded,
which avoids the White Screen Of Death problem described
in CB-9888.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/employeerepublic/cordova-plugin-wkwebview-engine 1.0.x-reload-on-resume-CB9888-3
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/cordova-plugin-wkwebview-engine/pull/11.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #11
commit 0966cd31b40ca1dd2f16f0d98f02919b8eb47e69
Author: mccraig mccraig of the clan mccraig <mccraigmccraig@gmail.com>
Date: 2016-06-13T21:41:05Z
CB-9888: (iOS) check & reload WKWebView
When an app is entering the foreground,
the WKWebView content process sometimes dies without
calling the webViewContentProcessDidTerminate delegate function.
This PR checks whether the content process has died, by
examining the title property of the WKWebView, which is nil
when the process has died.
If the process has died the WKWebView is reloaded,
which avoids the White Screen Of Death problem described
in CB-9888.
Github user shazron commented on the issue:
https://github.com/apache/cordova-plugin-wkwebview-engine/pull/11
Looks good, except that I would only log if it failed and you had to reload, since it might get verbose when a user app switches a lot. Wrap in a #define like so: https://github.com/apache/cordova-ios/blob/f75bf67438257132e739238ed579d73271b3a716/CordovaLib/Classes/Private/Plugins/CDVLocalStorage/CDVLocalStorage.m#L338
Github user mccraigmccraig commented on the issue:
https://github.com/apache/cordova-plugin-wkwebview-engine/pull/11
like this ? do you need a new PR with squashed commits ?
Github user shazron commented on the issue:
https://github.com/apache/cordova-plugin-wkwebview-engine/pull/11
That's great. I can squash when I merge. Thanks!
Commit 815ed0741b9ae30b343d6429bd8ff2ad37ec5790 in cordova-plugin-wkwebview-engine's branch refs/heads/master from mccraig mccraig of the clan mccraig
[ https://git-wip-us.apache.org/repos/asf?p=cordova-plugin-wkwebview-engine.git;h=815ed07 ]
CB-9888: (iOS) check & reload WKWebView
This closes #11
When an app is entering the foreground,
the WKWebView content process sometimes dies without
calling the webViewContentProcessDidTerminate delegate function.
This PR checks whether the content process has died, by
examining the title property of the WKWebView, which is nil
when the process has died.
If the process has died the WKWebView is reloaded,
which avoids the White Screen Of Death problem described
in CB-9888.
Commit 815ed0741b9ae30b343d6429bd8ff2ad37ec5790 in cordova-plugin-wkwebview-engine's branch refs/heads/master from mccraig mccraig of the clan mccraig
[ https://git-wip-us.apache.org/repos/asf?p=cordova-plugin-wkwebview-engine.git;h=815ed07 ]
CB-9888: (iOS) check & reload WKWebView
This closes #11
When an app is entering the foreground,
the WKWebView content process sometimes dies without
calling the webViewContentProcessDidTerminate delegate function.
This PR checks whether the content process has died, by
examining the title property of the WKWebView, which is nil
when the process has died.
If the process has died the WKWebView is reloaded,
which avoids the White Screen Of Death problem described
in CB-9888.
Github user asfgit closed the pull request at:
https://github.com/apache/cordova-plugin-wkwebview-engine/pull/11
Github user pwbs commented on the issue:
https://github.com/apache/cordova-plugin-wkwebview-engine/pull/11
Could we use `BOOL reload = (title == nil);` instead of `BOOL reload = ((title == nil) || [title isEqualToString:@""]);` ?
Github user mccraigmccraig commented on the issue:
https://github.com/apache/cordova-plugin-wkwebview-engine/pull/11
@pwbs you are presumably seeing crashes setting the title to `""` ?
Github user pwbs commented on the issue:
https://github.com/apache/cordova-plugin-wkwebview-engine/pull/11
My app sets the title to "" sometimes, which makes this plugin restart my app on each resume.
I guess that either the criterion `[title isEqualToString:@""]` shouldn't be used, or my app should never set the title to "". Perhaps both? I mean, isn't it weird to count on the status of the title to determine if we have the blank screen of death?
Github user mccraigmccraig commented on the issue:
https://github.com/apache/cordova-plugin-wkwebview-engine/pull/11
definitely it is weird - the test exists because the `webViewContentProcessDidTerminate` delegate function sometimes doesn't get called, which is presumably a bug in `WkWebView` itself
it was observed that the empty title is a test for this problem having occurred, and since there is no official API to determine the same, a weird but workable test is better than WSODs
the difficulty with this bug is that it only occurs irregularly - randomly, once every few days for me - so it's really hard to test solutions, and i don't know if the value which is matching the condition is actually `nil` or `""` - whether the condition can be reduced to `==nil` would depend on first figuring out the answer to this question
Github user pwbs commented on the issue:
https://github.com/apache/cordova-plugin-wkwebview-engine/pull/11
@mccraigmccraig thank you for your answers
I've started using a version where it's `BOOL reload = (title == nil); `. If I meet a WSOD with the app not restarting, I'll try investigate and tell you.
Github user mccraigmccraig commented on the issue:
https://github.com/apache/cordova-plugin-wkwebview-engine/pull/11
yw, also, since absence of evidence is not evidence of absence , perhaps keep an eye out for WSOD recoveries matching your `==nil` test - there's the obvious reload pause when the app comes into the foreground, and then you should be able to retrieve a log message like `CDVWKWebViewEngine reloading!` from the device logs
Github user pwbs commented on the issue:
https://github.com/apache/cordova-plugin-wkwebview-engine/pull/11
I remembered later that every time I inspected the contents of the WSOD, the page actually was a about:blank, so can't we test window.location instead?
Also, the reason why it ended up on about:blank was because it no longer had the rights for loading the local file:///...
Would this be a good lead?
Philippe Wang
(mail sent from a phone)
> On 11 Jul 2016, at 16:29, mccraigmccraig of the clan mccraig <notifications@github.com> wrote:
>
> yw, also, since absence of evidence is not evidence of absence , perhaps keep an eye out for WSOD recoveries matching your ==nil test - there's the obvious reload pause when the app comes into the foreground, and then you should be able to retrieve a log message like CDVWKWebViewEngine reloading! from the device logs
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub, or mute the thread.
>
Github user shazron commented on the issue:
https://github.com/apache/cordova-plugin-wkwebview-engine/pull/11
since if the title is empty results in a bug with this new fix, please file another issue so it can be tracked and resolved there.
Github user pwbs commented on the issue:
https://github.com/apache/cordova-plugin-wkwebview-engine/pull/11
Right, the issue is opened there: https://issues.apache.org/jira/browse/CB-11554
(Sorry I'm not too used to this "PR on github but issues on issues.apache.org")
Github user shazron commented on the issue:
https://github.com/apache/cordova-plugin-wkwebview-engine/pull/11
@mccraigmccraig please comment on my proposed modifications (see the comment about the unit tests) in https://issues.apache.org/jira/browse/CB-11554
Github user shazron commented on the issue:
https://github.com/apache/cordova-plugin-wkwebview-engine/pull/11
Filed https://github.com/apache/cordova-plugin-wkwebview-engine/pull/16
The Telerik plugin (at https://github.com/IjzerenHein/WKWebView ) has added basic crash detection to see if the page is returning a title or not. It's pretty basic, and unfortunately has to poll the page to see if it's returning a title tag, but it might be better than nothing. I am going to look at modifying this so that rather than polling, it'll check on foreground - if the title isn't there, display a "Ooops, something went wrong" page like Gmail does, and then reload that way. So this may not be an XPC issue but rather the com.apple.WebKit process crashing due to memory leaks. (I'm profiling my app now to see if any new memory leaks are present to confirm this is the case).