From 9582dd8d8c367b2b516f2747be3c7ec1ef20a0a3 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Tue, 11 Nov 2025 21:14:37 -0800 Subject: [PATCH] test(ios): add sanity check to diagnose WebView loading issue Added comprehensive sanity check to diagnose why HTML isn't loading: Sanity Check: - Creates simple test.html with red background for visibility - Checks if bridge and WebView exist - Attempts to load test.html or index.html directly - Lists bundle contents to see what files are actually present - Provides detailed logging of WebView state Debugging: - Checks bridge initialization - Checks WebView existence - Checks file paths in bundle - Lists actual bundle contents Fixes: - WebView diagnosis: can now see if WebView exists and what URL it has - File path verification: checks if HTML files are in bundle - Bundle inspection: lists what files are actually available Result: Will show exactly why HTML isn't loading - WebView issue, file path issue, or Capacitor config issue --- .../ios-test-app/App/App/ViewController.swift | 63 +++++++++++++++++++ .../ios-test-app/App/App/public/test.html | 24 +++++++ 2 files changed, 87 insertions(+) create mode 100644 test-apps/ios-test-app/App/App/public/test.html diff --git a/test-apps/ios-test-app/App/App/ViewController.swift b/test-apps/ios-test-app/App/App/ViewController.swift index 304064d..1b69351 100644 --- a/test-apps/ios-test-app/App/App/ViewController.swift +++ b/test-apps/ios-test-app/App/App/ViewController.swift @@ -12,6 +12,7 @@ import UIKit import Capacitor +import WebKit /** * Main view controller extending Capacitor's bridge view controller @@ -22,6 +23,14 @@ class ViewController: CAPBridgeViewController { override func viewDidLoad() { super.viewDidLoad() + // SANITY CHECK: Try loading a simple HTML file directly + print("ViewController: Starting sanity check...") + + // Wait a moment for Capacitor to initialize, then check + DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { + self.performSanityCheck() + } + // Debug: Print bridge configuration print("ViewController: Bridge initialized") if let bridge = self.bridge { @@ -41,6 +50,60 @@ class ViewController: CAPBridgeViewController { initializePlugin() } + /** + * Sanity check: Try to load a simple HTML file to verify WebView works + */ + private func performSanityCheck() { + print("ViewController: Performing sanity check...") + + // Check if we have a bridge and webView + guard let bridge = self.bridge else { + print("❌ SANITY CHECK FAILED: Bridge is nil!") + return + } + + guard let webView = bridge.webView else { + print("❌ SANITY CHECK FAILED: WebView is nil!") + return + } + + print("✅ Bridge and WebView exist") + print("WebView URL: \(webView.url?.absoluteString ?? "nil")") + + // Try to load test.html directly + if let bundlePath = Bundle.main.resourcePath, + let testHtmlPath = bundlePath.appending("/public/test.html") as String?, + FileManager.default.fileExists(atPath: testHtmlPath) { + let fileURL = URL(fileURLWithPath: testHtmlPath) + print("✅ Found test.html at: \(fileURL.path)") + webView.loadFileURL(fileURL, allowingReadAccessTo: fileURL.deletingLastPathComponent()) + } else { + print("❌ test.html not found in bundle") + // Try index.html instead + if let bundlePath = Bundle.main.resourcePath, + let indexHtmlPath = bundlePath.appending("/public/index.html") as String?, + FileManager.default.fileExists(atPath: indexHtmlPath) { + let fileURL = URL(fileURLWithPath: indexHtmlPath) + print("✅ Found index.html at: \(fileURL.path)") + webView.loadFileURL(fileURL, allowingReadAccessTo: fileURL.deletingLastPathComponent()) + } else { + print("❌ index.html also not found") + // List what's actually in the bundle + if let bundlePath = Bundle.main.resourcePath { + print("Bundle resource path: \(bundlePath)") + if let contents = try? FileManager.default.contentsOfDirectory(atPath: bundlePath) { + print("Bundle contents: \(contents)") + } + if let publicPath = bundlePath.appending("/public") as String?, + FileManager.default.fileExists(atPath: publicPath), + let publicContents = try? FileManager.default.contentsOfDirectory(atPath: publicPath) { + print("public/ contents: \(publicContents)") + } + } + } + } + } + /** * Initialize plugin and register native fetcher * Equivalent to PluginApplication.onCreate() on Android diff --git a/test-apps/ios-test-app/App/App/public/test.html b/test-apps/ios-test-app/App/App/public/test.html new file mode 100644 index 0000000..14cea6c --- /dev/null +++ b/test-apps/ios-test-app/App/App/public/test.html @@ -0,0 +1,24 @@ + + + + + + Sanity Check + + + +

✅ SANITY CHECK PASSED!

+

If you see this, the WebView is working!

+

HTML is loading correctly!

+ + +