WKWebView cannot load non-app-bound domains

WKWebView question...I've set up WKAppBoundDomains and am using limitsNavigationsToAppBoundDomains to enable evaluateJavaScript, Service Workers, etc.

That's all working great.

However, I'm no longer to able to load a WKWebView with any domain that is not one of the app-bound domains. For these other webviews, I don't need any of the special restricted APIs. I just want them to load and do basic website stuff.

My impression from the docs is that this should be fine. Does it require explicitly setting config.limitsNavigationsToAppBoundDomains = false?

Unfortunately I can't do that in all cases; some of the WKWebViews are created by external libraries where I can't edit the WKWebViewConfiguration

Is there another step I need to take? Or, maybe something with a ContentWorld?

Answered by jkadis in 782345022

For anyone else who comes across this in the future...

Once you upgrade some of your WKWebViews by using WKAppBoundDomains, other domains are downgraded and lose features.

A good example is evaluateJavaScript. It works in any WKWebView by default. But as soon as you create a WKAppBoundDomains array in your Info.plist, the default changes and becomes more strict.

Now, using evaluateJavaScript has two requirements: the domain of the WKWebView must be in the app-bound domains array and WKWebViewConfiguration.limitsNavigationsToAppBoundDomains must be true. If a WKWebView tries to use evaluateJavaScript but does not meet both of those requirements, it will fail loading.

Accepted Answer

For anyone else who comes across this in the future...

Once you upgrade some of your WKWebViews by using WKAppBoundDomains, other domains are downgraded and lose features.

A good example is evaluateJavaScript. It works in any WKWebView by default. But as soon as you create a WKAppBoundDomains array in your Info.plist, the default changes and becomes more strict.

Now, using evaluateJavaScript has two requirements: the domain of the WKWebView must be in the app-bound domains array and WKWebViewConfiguration.limitsNavigationsToAppBoundDomains must be true. If a WKWebView tries to use evaluateJavaScript but does not meet both of those requirements, it will fail loading.

WKWebView cannot load non-app-bound domains
 
 
Q