Closed gouteru closed 2 years ago
Here's info I found about WKwebview process. https://nevermeant.dev/handling-blank-wkwebviews/
Please help!
I have a similar issue. Now with cordova 11 I get stuck at the splash screen window on iOS after I kill (close) the app and reopen it. Any hints?
Maybe remove all plugins and add one by one again or clean build in Xcode (Product > Clean Build Folder). But for me it did not work.
edit: For me there seems to be a problem with the plugin cordova-plugin-screen-orientation. Maybe check for any plugins, which could stop your app from loading (OnDeviceReady event).
edit 2: If I set AutoHideSplashScreen to "true" I get whitescreen too. If I set it to "false" I still get stuck later when I kill and reload the app.
I have a similar issue. Now with cordova 11 I get stuck at the splash screen window on iOS after I kill (close) the app and reopen it. Any hints?
Maybe remove all plugins and add one by one again or clean build in Xcode (Product > Clean Build Folder). But for me it did not work.
edit: For me there seems to be a problem with the plugin cordova-plugin-screen-orientation. Maybe check for any plugins, which could stop your app from loading (OnDeviceReady event).
edit 2: If I set AutoHideSplashScreen to "true" I get whitescreen too. If I set it to "false" I still get stuck later when I kill and reload the app.
I think your issue is probably different from mine.
I could solve mine. It was an error in OnDeviceReady (i was acessing a device function before it was initialized). The error does not happen in desktop browser therefore I needed to debug with safari on physical device. GL to you!
Any update on this? I think iOS will terminate com.apple.Webkit.WebContent process anyway, but that can't be prevented. I think the real problem is that after reloading the webview with webViewWebContentProcessDidTerminate, app can't communicate properly with the reloaded webview process.
Can't detect an error like "Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service"? And if it can be detected, is there any way to reload webview again or restore communication with the WebContent process?
I think I found the root cause. The root cause was wkwebview.URL when webViewWebContentProcessDidTerminate was called. When I terminated "com.apple.WebKit.WebContent" process, webViewWebContentProcessDidTerminate was called but the reload url was incorrect as "app://localhost/index.html#/AppView". The url indicates one of my Vue JS component (the url is the one when app get into background) but not the initial url. Due to my app is based on Cordova and Vue framework and initial entry file should be "app://localhost/index.html". Then I modified ios/CordovaLib/Classes/Private/Plugins/CDVWebviewEngine/CDVWebviewEngine.m file as follows. The change worked fine. I could reproduced 100% of white screen issue with the above mentioned procedures however with the code change below I cannot reproduce the white screen issue. Since I am not familiar with ObjectiveC and CordovaLib fashion, please someone review the code below and let me know if it's okay or there is better code.
- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView
{
NSLog(@"webViewWebContentProcessDidTerminate wevView reload:");
NSString *sURL = @"app://localhost/index.html";
NSURL *url = [NSURL URLWithString:sURL];
NSLog(@"webViewWebContentProcessDidTerminate url: %@", [url absoluteString]);
NSLog(@"webViewWebContentProcessDidTerminate wevView.url: %@", [webView.URL absoluteString]);
[webView loadRequest:[NSURLRequest requestWithURL:url]];
// [webView reload];
}
Here's additional changes below.
- (BOOL)shouldReloadWebView:(NSURL*)location title:(NSString*)title
{
BOOL title_is_nil = (title == nil);
BOOL title_is_empty = ([title length] == 0); // added!
BOOL title_is_bad = (title_is_nil || title_is_empty); // added!
BOOL location_is_blank = [[location absoluteString] isEqualToString:@"about:blank"];
// BOOL reload = (title_is_nil || location_is_blank);
BOOL reload = (title_is_bad || location_is_blank); // added!
#ifdef DEBUG
NSLog(@"%@", @"CDVWebViewEngine shouldReloadWebView::");
NSLog(@"CDVWebViewEngine shouldReloadWebView title: %@", title);
NSLog(@"CDVWebViewEngine shouldReloadWebView title length: %u", [title length]); // // added!
NSLog(@"CDVWebViewEngine shouldReloadWebView title is nil: %u", title_is_nil);
NSLog(@"CDVWebViewEngine shouldReloadWebView location: %@", [location absoluteString]);
NSLog(@"CDVWebViewEngine shouldReloadWebView location is blank: %u", location_is_blank);
NSLog(@"CDVWebViewEngine shouldReloadWebView reload: %u", reload);
#endif
return reload;
}
- (void) onAppWillEnterForeground:(NSNotification*)notification {
if ([self shouldReloadWebView]) {
NSLog(@"%@", @"CDVWebViewEngine reloading!");
NSString *sURL = @"app://localhost/index.html";
NSURL *url = [NSURL URLWithString:sURL];
NSLog(@"onAppWillEnterForeground url: %@", [url absoluteString]);
[(WKWebView*)_engineWebView loadRequest:[NSURLRequest requestWithURL:url]];
// [(WKWebView*)_engineWebView reload];
}
}
I think shouldReloadWebView's title check is insufficient. In my app's case when WebContent process is terminated, title is not nil but empty string. So, empty string check should be added. With the changes above, my app works fine when WebContent process is terminated while app is in background. When app back in foreground, shouldReloadWebView detects properly and then load index.html.
With this change, when WebContent process is terminated while my app is in background, and then back in foreground, 2 functions "onAppWillEnterForeground" and "webViewWebContentProcessDidTerminate" do loadRequest. As long as my test, 2 times of loadRequest is not making any issue.
I think many of Cordova users will use additional JS frameworks such as Vue or React. So the url issue when WebContet process is terminated by iOS, is critical. When WebContent process is terminated, everything of JS code and state is cleared from memory. In that case, WebContent should load with index.html because app should go through its initialization to initialize Cordova plugins or firebase, etc. But currently, the url is as-is when app switched into background. Please consider to release update of cordova-ios.
Thanks @gouteru for your patch; I‘m running into similar issues with Cordova and meteor 2.7.1.
Applied your patch, with no success. Still WSOD. Meteor determines the port number for localhost based on App ID or something, in order to avoid conflicting ports with other apps. Does your patch take care of ports?
PS: Will try your method to reproduce the issue, which was not really possible before …
Applied your patch, with no success. Still WSOD. Meteor determines the port number for localhost based on App ID or something, in order to avoid conflicting ports with other apps. Does your patch take care of ports?
Sorry, I have no idea about ports.
@bratelefant see my comment in https://github.com/meteor/meteor/issues/11811#issuecomment-1113957240, maybe this fixes it?
@JH7 Just read your post, sounds reasonable for me. Will give it a shot and come back later.
What I did until now: Followed @gouteru 's instructions to reload the initial app url; didn't work at first try, due to "allow-navigation" errors, since the url didn't fit the scheme from cordovas config.xml. So i exchanged the url in the patch by http://localhost:<meteors-generated-portnumber>
, hardcoded for now. Next try will be your patch.
During testing I can confirm that the following method let's your quite easily reproduce the issue:
Apples "Instuments" app turns out to be quite helpful in monitoring, just learned that it existed... ;)
hello, i having an similar issue with ios cordova , ios app in simulator works fine, when i try to acess url call its shows nothing just white screen let me know of the solution as soon as possible cordova version -11.0.0 ios platforn -5.1.1 cordova plugins used - geolocat
I currently use a patchfile in my CI chain as follows:
src-cordova/fix-ios-black-screen.patch
diff --git a/CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m b/CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m
index a07bf290..82356def 100644
--- a/CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m
+++ b/CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m
@@ -270,7 +270,9 @@ static void * KVOContext = &KVOContext;
- (void) onAppWillEnterForeground:(NSNotification*)notification {
if ([self shouldReloadWebView]) {
NSLog(@"%@", @"CDVWebViewEngine reloading!");
- [(WKWebView*)_engineWebView reload];
+ NSURL* url = [((CDVViewController*) self.viewController) appUrl];
+ NSURLRequest* appReq = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:20.0];
+ [self loadRequest:appReq];
}
}
@@ -516,7 +518,11 @@ static void * KVOContext = &KVOContext;
- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView
{
- [webView reload];
+ CDVViewController *vc = (CDVViewController *)self.viewController;
+ [vc showLaunchScreen:true];
+ NSURL* url = [vc appUrl];
+ NSURLRequest* appReq = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:20.0];
+ [self loadRequest:appReq];
}
- (BOOL)defaultResourcePolicyForURL:(NSURL*)url
diff --git a/CordovaLib/Classes/Public/CDVViewController.h b/CordovaLib/Classes/Public/CDVViewController.h
index 81c7128f..52677c67 100644
--- a/CordovaLib/Classes/Public/CDVViewController.h
+++ b/CordovaLib/Classes/Public/CDVViewController.h
@@ -62,6 +62,7 @@
- (NSString*)appURLScheme;
- (NSURL*)errorURL;
+- (NSURL*)appUrl;
- (UIColor*)colorFromColorString:(NSString*)colorString CDV_DEPRECATED(7.0.0, "Use BackgroundColor in xcassets");
- (NSArray*)parseInterfaceOrientations:(NSArray*)orientations;
Somewhere in the CI chain (release_ios.sh)
cd src-cordova/platforms/ios
patch -N -p1 < ../../fix-ios-black-screen.patch
i think i have the same issue as you had, can you help out with the issue
Bug Report
Many of my app users has been reporting the issue that my app stops as white screen when it back to foreground from background.
Problem
What is expected to happen?
When back to foreground, app should display its webview contents properly.
What does actually happen?
When back to foreground, app displays white blank screen and no way to control by user(it looks freezing).
Information
I have been researching the issue a couple of months because I haven't reproduced. Finally I could reproduce the issue by killing 2 webview processes with Acitivity Monitor of MacOS.
Here’s the procedure.
When the app is back to foreground, app shows white screen but the killed 2 processes are reloaded in Activity Monitor view. But those 2 processes seem never communicate with app main process properly.
I guess, cordova-ios detects that webview processes are terminated and do webview.reload() but after that the reloaded processes are not communicating with app main process. Then my Javascript code is not loaded, not working, not rendering anything, so I can do nothing.
Here’s the log of Xcode.
Environment, Platform, Device
Various of iPhone hardware and iOS versions has been reported from my app users.
Version information
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