apache / cordova-ios

Apache Cordova iOS
https://cordova.apache.org/
Apache License 2.0
2.16k stars 988 forks source link

API to access WKWebViewConfiguration #977

Open jasonbekolay opened 4 years ago

jasonbekolay commented 4 years ago

Feature Request - API to access WKWebViewConfiguration

Motivation Behind Feature

Our team is upgrading from Cordova 5 to 6 and migrating from UIWebView to WKWebView. Our app used to use NSURLProtocol subclasses to handle certain requests from the UIWebView. This does not work with WKWebView. The new approach is to use WKURLSchemeHandler instances to handle requests made with a custom scheme. In order to do this, we need to register our scheme handlers with the WKWebViewConfiguration for the WebView. Right now, there does not seem to be a way to do this with public API. We also need to set the websiteDataStore on the WKWebViewConfiguration in order to set cookies for the WebView.

Feature Description

One option: Make CDVWebViewEngine a public class that class that can be extended. That way we can override createConfigurationFromSettings: and access WKWebViewConfiguration

Also open to any other option that provides access to WKWebViewConfiguration

Alternatives or Workarounds

Our current workaround is to use a post_install action in CocoaPods moves CDVWebViewEngine.h and CDVWebViewUIDelegate.h from private to public, then extending CDVWebViewEngine

CC: @lukemelia

luissilvaos commented 3 years ago

That would be a very useful feature!

ssraza commented 2 years ago

Any update on if/when this will gonna be supported?

pinthegrenade commented 1 year ago

Is there any progress in developing this feature?

globules-io commented 1 year ago

Bump, exact same need

breautek commented 1 year ago

Any update on if/when this will gonna be supported?

Due to the volunteer nature of Apache projects, we can't really provide any timelines. AFAIK no one is looking into this feature, but with that being said, if there is a need for this feature (which there appears to be), anybody willing is free to develop and prepare a PR. A PR will likely be best way to discuss potential solutions since reviewers can see the actual code changes.

Additionally if you have any questions regarding developing this feature, you may ask our Slack Community or subscribe to our Dev Mailing List.

globules-io commented 1 year ago

@breautek what about https://github.com/apache/cordova-ios/pull/1157

breautek commented 1 year ago

Looks like this might actually be resolved by https://github.com/apache/cordova-ios/pull/1050

jasonbekolay commented 1 year ago

Looks like this might actually be resolved by #1050

I haven't tried this myself yet, but looks like that would solve my need to set scheme handlers.

There is one additional need that emerged after creating this issue that I also resolved with my workaround of subclassing CDVWebViewEngine. We need to hook into some of the WKNavigationDelegate calls, particularly webViewWebContentProcessDidTerminate:. Since CDVWebViewEngine already implemented that, overriding it was the quickest path forward. If there public API that allows me to do that another way, then I would be able to remove my workaround.

GymotgM commented 4 months ago

Looks like this might actually be resolved by #1050

I haven't tried this myself yet, but looks like that would solve my need to set scheme handlers.

There is one additional need that emerged after creating this issue that I also resolved with my workaround of subclassing CDVWebViewEngine. We need to hook into some of the WKNavigationDelegate calls, particularly webViewWebContentProcessDidTerminate:. Since CDVWebViewEngine already implemented that, overriding it was the quickest path forward. If there public API that allows me to do that another way, then I would be able to remove my workaround.

@jasonbekolay The same issue, as the NSURLProtocol of UIWeb no longer exists, WKWebb needs to update it. How did you handle it? Can you share it

globules-io commented 4 months ago

@GymotgM It's not been pushed AFAIK

GymotgM commented 4 months ago

@breautek Hello, as WKWebb no longer uses NSURLProtocol, have you organized or referenced the materials for switching to WKURLSchemeHandler? I am looking forward to more information to solve the bridging problem after replacing UIWeb with WKWebb and listing it on the Apple Store

dpogue commented 4 months ago

@GymotgM Cordova iOS has used WKURLSchemeHandler for serving content since cordova-ios 6.0.0, released in 2020.