microsoft / cordova-plugin-code-push

Cordova plugin for CodePush
http://appcenter.ms
Other
643 stars 333 forks source link

Plugin not working with cordova-plugin-wkwebview-engine #603

Open Anuj-logiciel opened 4 years ago

Anuj-logiciel commented 4 years ago

Earlier I was using this plugin with UIWebview and all was working fine.

Now I have added WKWebview to my app & it stopped working.

Here are the few messages I am getting if I update a new release to appcenter.

--- [Log] [CodePush] Checking for update. (cordova.js, line 1732) --- [Log] [CodePush] An update is available. {"appVersion":"2.6.1","deploymentKey":"****","downloadUrl":"https://codepushupdates.azureedge.net/storagev2/HFFOqabT79WIYrshA21IVzaC2BSra70439e5-537f-462b-8871-9aad1d2794bc","isMandatory":false,"label":"v21","packageHash":"81ef57a81a32f9b77cd084000e449f1e1a586ef47f7fbc53dddc6b4bb360cb04","packageSize":17368484,"failedInstall":false} (cordova.js, line 1732) --- [Log] [CodePush] Downloading update (cordova.js, line 1732) --- [Log] [CodePush] Package download success: {"deploymentKey":"****","label":"v21","appVersion":"2.6.1","isMandatory":false,"packageHash":"81ef57a81a32f9b77cd084000e449f1e1a586ef47f7fbc53dddc6b4bb360cb04","isFirstRun":false,"failedInstall":false,"localPath":"cdvfile://localhost/library-nosync/codepush/download/update.zip"} (cordova.js, line 1732) --- [Log] [CodePush] Installing update (cordova.js, line 1732)

It stucks after the above messages and the app never gets updated. Any quick help would be appreciated. Thanks!

ckarlss0n commented 4 years ago

We're also experiencing problems at my client when using WKWebView, which is a shame because we would love to use both CodePush and WKWebView.

So far we've tested both cordova-plugin-ionic-webview as well as cordova-plugin-wkwebview-engine for our Ionic 3 application. When the application gets restarted after installing the CodePush update, we just see a white screen. When looking at the history tab in Safari we can see that it tries to find the index.html file from the downloaded bundle at some path under the ionic://localhost protocol. I'm not sure if it's actually able to find it (I guess not?), but at least we do not get any 404 errors.

It would be great if we could updates from the people at Microsoft regarding this (there are multiple issues posted about WKWebView), so we know whether or not we can expect a fix to be implemented shortly.

sithwarrior commented 4 years ago

You might want to post the specific versions of your plugins etc.

We are running an app with cordova-plugin-ionic-webview and the latest codepush in production without issue.

However we are using cordova-plugin-ionic-webview 2.5.2 to preserve the "old" url scheme format.

Anuj-logiciel commented 4 years ago

For adding info to my issue, I would like to add more info here-

I am using - This WKWebview plugin

I also have Also reported issue on its plugin.

jacobg commented 4 years ago

Has anyone tried the cordova-plugin-wkwebview-file-xhr plugin to see if it works with code push? https://github.com/oracle/cordova-plugin-wkwebview-file-xhr

GimpMaster commented 4 years ago

following this issue...

trinvh commented 4 years ago

Following this issue...

tudordumitriu commented 4 years ago

Same issue here I did try by installing cordova-plugin-wkwebview-file-xhr (even though we already have https://github.com/TheMattRay/cordova-plugin-wkwebviewxhrfix) and the behavior is exactly the same:

  1. Downloading update
  2. Package download success (so I don't think it has anything with CSP or even XHR)
  3. Installing update - where it gets stuck
  4. Restarting the app (assuming that on resume you do a codepush.sync()) displays: Sync already in Progress Anyone any hints where to start looking, since in the official plugin page they say: "iOS (cordova-ios 3.9.0+) - Note: In order to use CodePush along with the cordova-plugin-wkwebview-engine plugin, you need to install v1.5.1-beta+ version of cordova-plugin-code-push, which includes full support for apps using either WebView." so maybe this is not the real issue
alexhisen commented 4 years ago

FYI, we are not experiencing any issues with codepush with these versions:

    <engine name="ios" spec="^5.1.1" />
    <plugin name="cordova-plugin-zip" spec="^3.1.0" />
    <plugin name="cordova-plugin-file-transfer" spec="^1.7.1" />
    <plugin name="cordova-plugin-file" spec="^4.3.1" />
    <plugin name="cordova-plugin-code-push" spec="^1.12.0" />
    <plugin name="cordova-plugin-wkwebview-engine" spec="^1.2.1" />
    <plugin name="cordova-plugin-wkwebviewxhrfix" spec="git+https://github.com/TheMattRay/cordova-plugin-wkwebviewxhrfix.git" />

The code-push plugin (not declared in config.xml) is at slightly older 3.0.1. Our initial update is usually installed on app restart and subsequent updates are installed on app resume.

Pigsnuck commented 4 years ago

FYI, we are not experiencing any issues with codepush with these versions:

    <engine name="ios" spec="^5.1.1" />
    <plugin name="cordova-plugin-zip" spec="^3.1.0" />
    <plugin name="cordova-plugin-file-transfer" spec="^1.7.1" />
    <plugin name="cordova-plugin-file" spec="^4.3.1" />
    <plugin name="cordova-plugin-code-push" spec="^1.12.0" />
    <plugin name="cordova-plugin-wkwebview-engine" spec="^1.2.1" />
    <plugin name="cordova-plugin-wkwebviewxhrfix" spec="git+https://github.com/TheMattRay/cordova-plugin-wkwebviewxhrfix.git" />

The code-push plugin (not declared in config.xml) is at slightly older 3.0.1. Our initial update is usually installed on app restart and subsequent updates are installed on app resume.

Hi Alex,

Can you please clarify what you mean by "the code-push plugin...is slightly older 3.0.1"? This is not a valid version for cordova-plugin-code-push, and the version listed in your config.xml is 1.12.0.

I am also have issues getting code push to work with WkWebView, and I am trying to replicate your setup.

alexhisen commented 4 years ago

code-push is an 'internal' dependency of the cordova-plugin-code-push and has its own plugin package and version. If you install from scratch, I think you'll get a newer version of code-push than 3.0.1 right now as it gets the latest, but since we had it previously and it satisfies the dependency requirement, it gets used. I don't know if the older version matters or not.

shaik-azmat commented 4 years ago

Thank you alexhisen, it worked for me

tudordumitriu commented 4 years ago

Hi there Finally being forced by Apple we had to step into, and this issue seems to have been a space in our Project Name https://github.com/microsoft/cordova-plugin-code-push/issues/618

Krasavinigor commented 4 years ago

Hi there!

  1. Cordova-plugin-code-push is updated to the new version (1.13.0)
  2. Also, we opened PR for fixing issue with wkwebview: https://github.com/microsoft/cordova-plugin-code-push/pull/642

@Anuj-logiciel Could you please test your project with new changes?

alexandergoncharov-zz commented 4 years ago

Hi all, We merged this PR https://github.com/microsoft/cordova-plugin-code-push/pull/642 and published new 1.13.1 version. Could you please test it and let us know if it fixed your issue?

Pigsnuck commented 4 years ago

Hi Alexander,

1.13.1 did not fix the issue for me. The error message "Failed to load webpage with error: unsupported URL" now pops up as an alert instead of just in the XCode output.

I also tried updating the code-push dependency plugin from 3.0.1 to 4.0.2. The same error pops up when starting the app as before.

My Objective-C skills are very rusty, but I took a look myself. It appears that CDVWKWebViewEngine+CodePush.m assumes that Ionic is being used. THIS IS NOT THE CASE - I AM USING PURE CORDOVA. This method fiddles with the URL and changes it to "ionic://localhost", which is invalid in the pure Cordova case. If I comment out the code below, everything works for me.

- (id)loadPluginRequest:(NSURLRequest *)request {
//    if (request.URL.fileURL) {
//        NSDictionary* settings = self.commandDelegate.settings;
//        NSString *bind = [settings cordovaSettingForKey:@"Hostname"];
//        if(bind == nil){
//            bind = @"localhost";
//        }
//        NSString *scheme = [settings cordovaSettingForKey:@"iosScheme"];
//        if(scheme == nil || [scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"]  || [scheme isEqualToString:@"file"]){
//            scheme = @"ionic";
//        }
//        NSString *CDV_LOCAL_SERVER = [NSString stringWithFormat:@"%@://%@", scheme, bind];
//
//        NSURL* startURL = [NSURL URLWithString:((CDVViewController *)self.viewController).startPage];
//        NSString* startFilePath = [self.commandDelegate pathForResource:[startURL path]];
//        NSURL *url = [[NSURL URLWithString:CDV_LOCAL_SERVER] URLByAppendingPathComponent:request.URL.path];
//        if ([request.URL.path isEqualToString:startFilePath]) {
//            url = [NSURL URLWithString:CDV_LOCAL_SERVER];
//        }
//        if(request.URL.query) {
//            url = [NSURL URLWithString:[@"?" stringByAppendingString:request.URL.query] relativeToURL:url];
//        }
//        if(request.URL.fragment) {
//            url = [NSURL URLWithString:[@"#" stringByAppendingString:request.URL.fragment] relativeToURL:url];
//        }
//        request = [NSURLRequest requestWithURL:url];
//    }
    return [(WKWebView*)self.engineWebView loadRequest:request];
}

Thanks for your attention on this issue.

Krasavinigor commented 4 years ago

Hi all,

If you still have issues could you please provide some demo app with reproducing issue and reprosteps? Unfortunately, we can't reproduce any issues with it.

Pigsnuck commented 4 years ago

Hi,

Unfortunately, I am not permitted to share my app here for commercial reasons.

Reproducing should be fairly simple though. Just create a standard Cordova app that doesn't use ionic, then you should be able to easily reproduce the behaviour.

Krasavinigor commented 4 years ago

@Pigsnuck! Unfortunately, I couldn't. I use a sample in the codepush repo. It's more helpful for investigating if you will share pure project with codepush plugin and this issue.

Pigsnuck commented 4 years ago

@Krasavinigor I would be happy to create a pure Cordova project exhibiting the behaviour, but I am on vacation for the next 3 weeks. If you can keep this ticket open that long, I will create a project so you can replicate the error in development.

sithwarrior commented 4 years ago

@Krasavinigor I wrote up how to test it using the sample apps in the codepush repo. The issue seems to be the custom url scheme

https://github.com/microsoft/cordova-plugin-code-push/issues/624#issuecomment-684513863

Krasavinigor commented 4 years ago

Thank @sithwarrior! I reproduced this issue. We will investigate it as soon as possible.

luke-lewandowski commented 4 years ago

Hi Alexander,

1.13.1 did not fix the issue for me. The error message "Failed to load webpage with error: unsupported URL" now pops up as an alert instead of just in the XCode output.

I also tried updating the code-push dependency plugin from 3.0.1 to 4.0.2. The same error pops up when starting the app as before.

My Objective-C skills are very rusty, but I took a look myself. It appears that CDVWKWebViewEngine+CodePush.m assumes that Ionic is being used. THIS IS NOT THE CASE - I AM USING PURE CORDOVA. This method fiddles with the URL and changes it to "ionic://localhost", which is invalid in the pure Cordova case. If I comment out the code below, everything works for me.

- (id)loadPluginRequest:(NSURLRequest *)request {
//    if (request.URL.fileURL) {
//        NSDictionary* settings = self.commandDelegate.settings;
//        NSString *bind = [settings cordovaSettingForKey:@"Hostname"];
//        if(bind == nil){
//            bind = @"localhost";
//        }
//        NSString *scheme = [settings cordovaSettingForKey:@"iosScheme"];
//        if(scheme == nil || [scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"]  || [scheme isEqualToString:@"file"]){
//            scheme = @"ionic";
//        }
//        NSString *CDV_LOCAL_SERVER = [NSString stringWithFormat:@"%@://%@", scheme, bind];
//
//        NSURL* startURL = [NSURL URLWithString:((CDVViewController *)self.viewController).startPage];
//        NSString* startFilePath = [self.commandDelegate pathForResource:[startURL path]];
//        NSURL *url = [[NSURL URLWithString:CDV_LOCAL_SERVER] URLByAppendingPathComponent:request.URL.path];
//        if ([request.URL.path isEqualToString:startFilePath]) {
//            url = [NSURL URLWithString:CDV_LOCAL_SERVER];
//        }
//        if(request.URL.query) {
//            url = [NSURL URLWithString:[@"?" stringByAppendingString:request.URL.query] relativeToURL:url];
//        }
//        if(request.URL.fragment) {
//            url = [NSURL URLWithString:[@"#" stringByAppendingString:request.URL.fragment] relativeToURL:url];
//        }
//        request = [NSURLRequest requestWithURL:url];
//    }
    return [(WKWebView*)self.engineWebView loadRequest:request];
}

Thanks for your attention on this issue.

As per this user - commenting out this section does fix the issue. I'm on Cordova and not Ionic - and this was replacing the request with ionic://localhost.

Pigsnuck commented 4 years ago

@luke-lewandowski I created a fork with my "not really a fix" if you're interested. My Cordova app is working in production with the forked code.

sithwarrior commented 4 years ago

Thank @sithwarrior! I reproduced this issue. We will investigate it as soon as possible.

Any update on this? We would really like to push an update for our app.

mark-divitt commented 4 years ago

Any news? This is a critical bug that makes it impossible to push updates to an iOS device...