cordova-plugin-code-push icon indicating copy to clipboard operation
cordova-plugin-code-push copied to clipboard

Plugin not working with cordova-plugin-wkwebview-engine

Open Anuj-logiciel opened this issue 5 years ago • 25 comments

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!

Anuj-logiciel avatar Feb 25 '20 11:02 Anuj-logiciel

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.

ckarlss0n avatar Feb 25 '20 13:02 ckarlss0n

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.

sithwarrior avatar Feb 28 '20 08:02 sithwarrior

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.

Anuj-logiciel avatar Feb 28 '20 11:02 Anuj-logiciel

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

jacobg avatar Feb 28 '20 12:02 jacobg

following this issue...

JoshuaHintze avatar Mar 05 '20 22:03 JoshuaHintze

Following this issue...

trinvh avatar Mar 09 '20 05:03 trinvh

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

tudordumitriu avatar Mar 20 '20 07:03 tudordumitriu

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.

alexhisen avatar Mar 26 '20 03:03 alexhisen

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.

Pigsnuck avatar May 18 '20 13:05 Pigsnuck

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.

alexhisen avatar May 20 '20 20:05 alexhisen

Thank you alexhisen, it worked for me

shaik-azmat avatar May 27 '20 16:05 shaik-azmat

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

tudordumitriu avatar May 29 '20 09:05 tudordumitriu

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?

Krasavinigor avatar Aug 28 '20 09:08 Krasavinigor

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?

alexandergoncharov-zz avatar Aug 28 '20 14:08 alexandergoncharov-zz

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.

Pigsnuck avatar Aug 29 '20 13:08 Pigsnuck

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.

Krasavinigor avatar Aug 31 '20 07:08 Krasavinigor

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.

Pigsnuck avatar Aug 31 '20 10:08 Pigsnuck

@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.

Krasavinigor avatar Aug 31 '20 15:08 Krasavinigor

@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.

Pigsnuck avatar Sep 01 '20 07:09 Pigsnuck

@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

sithwarrior avatar Sep 01 '20 07:09 sithwarrior

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

Krasavinigor avatar Sep 01 '20 10:09 Krasavinigor

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.

luke-lewandowski avatar Sep 04 '20 10:09 luke-lewandowski

@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.

Pigsnuck avatar Sep 04 '20 20:09 Pigsnuck

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.

sithwarrior avatar Sep 14 '20 09:09 sithwarrior

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

mark-divitt avatar Oct 05 '20 17:10 mark-divitt