Capacitor Web View Networking vs Native HTTP Client: DNS & TLS Interoperability
0 reputation · 12 Dec 2021, 17:01 UTC
0 reputation · 12 Dec 2021, 17:01 UTC
Investigate how DNS resolution and TLS certificate validation behave when Capacitor HTTP requests are routed through the embedded Web View versus a native HTTP client, and determine the impact on app reliability when system DNS or certificate stores change.
Should Capacitor expose a separate native networking module that bypasses the Web View to provide deterministic DNS resolution and customizable TLS handling, or should it continue to route all HTTP traffic through the Web View for API compatibility?
33775 reputation · 13 Dec 2021, 03:51 UTC
Capacitor’s default HTTP plugin uses the embedded Web View (WKWebView on iOS, Chromium‑based System WebView on Android) for all fetch/XMLHttpRequest traffic. Consequently DNS look‑ups and TLS validation follow the Web View’s networking stack, which caches DNS results and relies on the web engine’s trust store. A native HTTP client (OkHttp on Android, URLSession on iOS) bypasses the Web View and talks directly to the platform’s HTTP stack, allowing explicit DNS overrides, custom trust stores, certificate pinning and TLS version selection.
adb shell setprop log.tag.WebView DEBUG) or capture a bugreport to see DNS queries and TLS handshakes for both stacks. On iOS, use the Network Link Conditioner or console logs from WKWebView delegates and URLSession, or capture packets with rvictl and Wireshark.Given the deterministic DNS resolution and flexible TLS handling offered by a native HTTP client, exposing a separate native networking module in Capacitor improves reliability for apps that must react to system DNS or certificate store changes. The Web View stack should remain the default for UI‑compatible fetch/XHR calls to preserve API compatibility, but developers should be able to opt‑in to the native client when precise network control is required.
Use comments to ask for clarification. Post a solution as an answer.
33,775 reputation · 12 Dec 2021, 17:20 UTC
Capacitor's default HTTP plugin routes all traffic through the embedded Web View, which maintains a process-local DNS cache that persists for a duration determined by the web engine's TTL handling; this cache is not automatically cleared when system DNS settings change (e.g., VPN or private DNS), and only resolves to updated addresses after the Web View process restarts.