MobileChromeApps / cordova-plugin-service-worker

163 stars 37 forks source link

Building for cordova-ios 4.0.0 and wkWebView beta fails #15

Open runspired opened 9 years ago

runspired commented 9 years ago
/Plugins/cordova-plugin-service-worker/CDVServiceWorker.m:141:19: warning: 
      unused variable 'options' [-Wunused-variable]
    NSDictionary *options = [command argumentAtIndex:1];
                  ^
/Plugins/cordova-plugin-service-worker/CDVServiceWorker.m:285:32: error: 
      no known class method for selector 'dataFromBase64String:'
        NSData *data = [NSData dataFromBase64String:[response[@"body"] toString]];
                               ^~~~~~~~~~~~~~~~~~~~
jamessharp commented 8 years ago

This code fixes the build, however WKWebView doesn't allow interception of network requests which means the plugin doesn't (can't ?) work anyway.

runspired commented 8 years ago

@jamessharp hrm, so it's still goof for a lot of the uses of a service worker (data sync), but not for asset cacheing. I'm ok with that personally since on cordova I'm serving from local assets, but would be nice if this was possible. Does the cordova-whitelist plugin not intercept?

jamessharp commented 8 years ago

Yes, I suspect everything but asset cacheing/interception will work OK (I haven't tested it though). Chrome on iOS is still using UIWebView because of this issue (among other things). See this meta-bug for discussion. You could hack round it for XHR requests by using something like xhook but I don't think it's possible for standard requests (images, css, fonts etc).

clelland commented 8 years ago

@jamessharp That's right, there's no way to intercept network requests with WKWebView; this plugin won't work with cordova-plugin-wkwebview-engine, at least for fetch events.

@runspired, I don't believe that cordova-whitelist works on WKWebView either; the suggestion there is to use CSP to control what the web content of your application has access to

runspired commented 8 years ago

If you haven't already, you should open issue tickets with Apple for both ServiceWorker support (I've already done so) and for wkWebView to support intercepting network requests (I'm about to do so).

runspired commented 8 years ago

@jamessharp @clelland I've often wondered if you could "hook" the src attribute of img and script programmatically, I'll investigate that. Alternative idea, a script included before anything else that grabs src and link attributes from script img and link and removes them, then adds a path from cache returned by the service worker.