cordova-ios icon indicating copy to clipboard operation
cordova-ios copied to clipboard

API to access WKWebViewConfiguration

Open jasonbekolay opened this issue 4 years ago • 12 comments

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

jasonbekolay avatar Aug 28 '20 20:08 jasonbekolay

That would be a very useful feature!

luissilvaos avatar Oct 08 '20 09:10 luissilvaos

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

ssraza avatar Sep 15 '21 18:09 ssraza

Is there any progress in developing this feature?

pinthegrenade avatar Sep 08 '22 12:09 pinthegrenade

Bump, exact same need

globules-io avatar Oct 18 '22 13:10 globules-io

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.

breautek avatar Oct 18 '22 13:10 breautek

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

globules-io avatar Oct 18 '22 13:10 globules-io

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

breautek avatar Oct 18 '22 14:10 breautek

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 avatar Oct 20 '22 15:10 jasonbekolay

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

GymotgM avatar Apr 08 '24 09:04 GymotgM

@GymotgM It's not been pushed AFAIK

globules-io avatar Apr 08 '24 09:04 globules-io

@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

GymotgM avatar Apr 12 '24 02:04 GymotgM

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

dpogue avatar Apr 12 '24 02:04 dpogue