-
Notifications
You must be signed in to change notification settings - Fork 0
WKWebView
Ken Harris edited this page Sep 23, 2020
·
22 revisions
WebView
(on Mac) is the old WebKit view that runs entirely in-process. WKWebView
is the new hotness that runs in its own process, for performance and security (so they claim). It has a number of rather significant downsides which made it useless to me for the first several years. Even in 2020, it lags WebView in features, in many ways:
-
It ignores custom[NS]URLProtocol
s. It'll load the protocol and claim to support it, but then ignore it completely.- In 10.13, there's a WKURLSchemeHandler! Note that the interface is completely different -- this means re-architecting, not just updating some method names.
-
Xcode 8 can't add it in IB.(FB5550470)- Xcode 9 can! ... sort of.
- You get a "Reload" context menu (and "Open in New Window", etc?), and it's not easy to disable (FB8653798)
- Printing is broken (36557179)
- No way to use a user stylesheet (37652333)
- To set any configuration on it (like a WKURLSchemeHandler), you need to pass that configuration to its
init
, which means you can't create it in IB. (FB8653162) - Requires the
security.network.client
entitlement even for displaying static text. (FB8653139) - webView:stop: is only called for loading cancellations, i.e., usually never. There’s no easy user “cleanup” point for tasks.
- The stack traces you get from WKWebView-related crashes are pretty awful. Mangled names.
- When you call setURLSchemeHandler, if the scheme is built-in, you get an exception. You're supposed to use WKWebView.handlesURLScheme to check first (and keep adding suffixes or something until you find a free one?). In their WWDC video, they say to prefix it with your company name, like “apple-local” (instead of just “local”). There’s no built-in way to say “give me something which I'm free to use”.