This sample project tries to detect if the page is loaded in iOS WebView (WKWebView, SFSafariViewController and UIWebView)
Tested on iOS 16.
Demo: https://milen-yordanov.github.io/detect-ios-webview/index.html
It uses two methods for iOS WebView detection:
See: https://developer.apple.com/documentation/webkit/wkscriptmessagehandler
window.webkit.messageHandlers is defined in WKWebView with WKScriptMessageHandler
- if window.webkit.messageHandlers is present then it is 100% WKWebView
- if window.webkit.messageHandlers is not present then it could be: 2.1) WKWebView without WKScriptMessageHandler 2.2) not a WKWebView
It relies on iOS 100vh and 100% sizing calculation.
For 100vh, 100% and position: fixed
see:
https://developers.google.com/web/updates/2016/12/url-bar-resizing