SlideShare a Scribd company logo
WKWebView in Production
7 things you should know about
Jeremy Wiebe
Senior Engineer, Lead
In the beginning there
was UIWebView
What is UIWebView?
• Original web rendering component
introduced in iOS 2.0
• This is what was historically used to build out
hybrid apps or load any web content inside an
iOS app
Remember this?
UIWebView !== Safari
• Mobile Safari tends to load pages 2-3x faster
than a UIWebView
• Changes and fixes applied to Safari often not
ported into UIWebView
• UIWebview is clunky, crashy, leaks memory
• Scrolling blocks images loading and animation
• Different JavaScript engine than Safari (not Nitro)
Why does UIWebView not have Nitro?
Nitro is excluded because
Apple wanted to make hybrid
apps less performant and
force everybody to use their
native platform
Excluded due to security
reasons. Running a Just-In-
Time compiler requires
marking pages in RAM as
executable - iOS does not
allow this out of security
concerns (except in Safari)
Cynical Answer Real Answer
Introducing
WKWebView
WKWebView
Introduced in iOS 8 to give developers a performant
webview (“same” performance as Safari)
WKWebView's rendering is all done in a
separate process owned by the WKWebView
WKWebView == WebKit
Benefits of WKWebView
Better HTML 5 Support
WKWebView also gives us…
• Significant performance gains in WebGL
applications (though supported in UIWebview)
• Less "crashy" behaviour when rendering bugs
are triggered from HTML/CSS/JavaScript
More benefits!
• Faster JavaScript and page rendering(thanks Nitro!)
• 60fps interactive scrolling
• Better communication between Swift and JS
(we haven’t experimented with this yet)
• Since we are sharing the JS engine with
Safari, WKWebView should be better
maintained and more reliable
How do I implement WKWebView?
• Don’t worry, there’s a ton of great
documentation!
How do I implement WKWebView?
• Don’t worry, there’s a ton of great
documentation!
How do I implement WKWebView?
• Don’t worry, there’s a ton of great
documentation!
• What was formerly a single class (UIWebView) and
protocol (UIWebViewDelegate) is now 14 classes and 3
protocols (WKNavigationDelegate, WKScriptMessageHandler,
WKUIDelegate)
• Other than class docs (and StackOverflow), no official
“How-To WKWebView” from Apple
WKWebView Related Classes
WKBackForwardList
WKBackForwardListItem
WKFrameInfo
WKNavigation
WKNavigationAction
WKNavigationResponse
WKPreferences
WKProcessPool
WKScriptMessage
WKSecurityOrigin
WKUserContentController
WKUserScript
WKWebViewConfiguration
WKWebsiteDataRecord
WKWebsiteDataStore
WKWindowFeatures
WKWebView
More code required
• Automatically handled by UIWebView
• App store links
• JS alerts, confirms, inputs
• Sharing cookies between web views
The 7 Wonders
Disappointments of
WKWebView
(and what to do about them)
Cannot load bundled content
in iOS 8
#1
Cannot load bundled content
• Critical to many apps
• UIWebView:
• webView!.loadRequest(request)
How do I implement WKWebView?
• High-level: copy the files we need to load into a
/tmp directory that we can load files from
• Alternative: serve files we need from a web
server in the app
• Solution: Fixed in iOS 9
WKWebView in Production
Cannot intercept POST
requests
#2
Cannot intercept POST requests
• POST bodies are missing in NSURLRequest
sent to delegate methods
• Solution: for now leave it -- in line with
Android behaviour
• Good news: WebKit forums indicate this is a
bug and there seems to be a bit of traction
Broken UI state preservation
#3
No state preservation participation
• WKWebView doesn’t conform to the state
preservation API (no restorationIdentifier)
• In Astro its used to reduce memory footprint
and prevent crashes
• Solution: build our own by saving the last
known URL
WSOD: White Screen of Death
#4
• Seeing some webviews display about:blank for
no reason upon navigating back
• Appears to be a memory issue
WSOD: White Screen of Death
WSOD - Our Solution
We poll each webview that we manage and not currently visible (in the view hierarchy)
Views Appear Halfway Down
#5
• Happens when the frame is not set before load
completes http://www.openradar.me/22855188
• Had to get creative on this one.
• Turns out, duplicate <head> tags are ignored…
• … so we create a <head> tag at the beginning JUST
to scroll back up
Views Appear Halfway Down
Our Solution
View Doesn’t Render
Until Visible
#6
View Doesn’t Render Until Visible
• Big problem for preloading tabs in a tab bar
layout
• Bigger problem if you rely on Javascript to run
in those webviews
• Solution is an off-screen “holding pen” for web
views not currently visible
Our Solution
Broken or Self-Signed
Certs in iOS 8
#7
WKWebView and Certs
• Bug in WKWebView where the documented
way of doing custom analysis of SSL
certificates is broken
• webView(_:didReceiveAuthenticationChallenge:completionHandler:)
is never called
• Important for internal use
• No workaround
Other Weird Bugs
Need to know about these:
• When app is sent to background, JS stops executing in ~10sec
while native code (and JS in UIWebView) keeps running for ~3
min until completely suspended by OS.
• Unlike UIWebView, the webView.URL property is updated to
the navigation target the first delegate method is called by
WKWebView.
• App store links don’t work by default -- have to intercept
requests (http://atmarkplant.com/ios-wkwebview-tips/#applink)
Are others using it?
Who uses WKWebView?
WKWebView is
enabled by default in
our hybrid app SDK
astro.mobify.com
Q&A
Jeremy Wiebe

More Related Content

PPTX
Πρωτοχριστιανικά Σύμβολα και Παραστάσεις.pptx
PPT
θρησκευτική μεταρρύθμιση
PDF
Takeuchi tb290 hydraulic excavator service repair workshop manual (serial no....
PPTX
Alla scoperta dei Vector Database e dei RAG
PDF
10. ο ανθρωπος στο αρχικο μεγαλειο του
PPTX
Δομήνικος Θεοτοκόπουλος
PDF
[iOS 8] 測れる!パフォーマンス
PDF
新しいTest flightの使い方(20140918)
Πρωτοχριστιανικά Σύμβολα και Παραστάσεις.pptx
θρησκευτική μεταρρύθμιση
Takeuchi tb290 hydraulic excavator service repair workshop manual (serial no....
Alla scoperta dei Vector Database e dei RAG
10. ο ανθρωπος στο αρχικο μεγαλειο του
Δομήνικος Θεοτοκόπουλος
[iOS 8] 測れる!パフォーマンス
新しいTest flightの使い方(20140918)

Similar to WKWebView in Production (20)

PDF
WebView Development Pitfalls
PDF
WebView security on iOS (EN)
PDF
Native-Javascript Bridging Using WKWebViews in iOS8
PDF
Gdg dev fest hybrid apps your own mini-cordova
PPTX
do u webview?
PDF
Mobile is still Fresh
PPTX
04 objective-c session 4
PDF
Webview: The fifth element
PDF
"WebView, the fifth element" por @fernando_cejas
PDF
Ios7 - The good the bad & the changes
KEY
Mistakes I Made Building Netflix for the iPhone
PDF
The WebView Role in Hybrid Applications
PDF
New things about Cordova 4.0
PPTX
Progressive web apps
PPTX
Mobile and IBM Worklight Best Practices
PDF
Nishimura finding vulnerabilities-in-firefox-for-i-os-(nishimunea)
PDF
Hybrid apps - Your own mini Cordova
PDF
Stanfy MadCode Meetup#6: Apple Watch. First Steps.
PDF
Revue des annonces WWDC2015
PDF
Mobile Hybrid Applications dan Android Web View Widget
WebView Development Pitfalls
WebView security on iOS (EN)
Native-Javascript Bridging Using WKWebViews in iOS8
Gdg dev fest hybrid apps your own mini-cordova
do u webview?
Mobile is still Fresh
04 objective-c session 4
Webview: The fifth element
"WebView, the fifth element" por @fernando_cejas
Ios7 - The good the bad & the changes
Mistakes I Made Building Netflix for the iPhone
The WebView Role in Hybrid Applications
New things about Cordova 4.0
Progressive web apps
Mobile and IBM Worklight Best Practices
Nishimura finding vulnerabilities-in-firefox-for-i-os-(nishimunea)
Hybrid apps - Your own mini Cordova
Stanfy MadCode Meetup#6: Apple Watch. First Steps.
Revue des annonces WWDC2015
Mobile Hybrid Applications dan Android Web View Widget
Ad

Recently uploaded (20)

PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
August Patch Tuesday
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
DP Operators-handbook-extract for the Mautical Institute
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
1. Introduction to Computer Programming.pptx
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Zenith AI: Advanced Artificial Intelligence
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
STKI Israel Market Study 2025 version august
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Developing a website for English-speaking practice to English as a foreign la...
WOOl fibre morphology and structure.pdf for textiles
observCloud-Native Containerability and monitoring.pptx
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
1 - Historical Antecedents, Social Consideration.pdf
August Patch Tuesday
NewMind AI Weekly Chronicles – August ’25 Week III
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
Web App vs Mobile App What Should You Build First.pdf
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
DP Operators-handbook-extract for the Mautical Institute
Final SEM Unit 1 for mit wpu at pune .pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
1. Introduction to Computer Programming.pptx
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Zenith AI: Advanced Artificial Intelligence
Group 1 Presentation -Planning and Decision Making .pptx
STKI Israel Market Study 2025 version august
Ad

WKWebView in Production