From 614042c3bdca9d0322030e6eec032587c572d736 Mon Sep 17 00:00:00 2001 From: Ilyas Hallak Date: Fri, 10 Oct 2025 19:46:09 +0200 Subject: [PATCH] fix: Simplify NativeWebView CSS and JavaScript height detection CSS Changes: - Removed all overflow/max-width/word-break rules from body/html - Simplified to match WebView.swift CSS structure exactly - Only img keeps max-width: 100% - Removed box-sizing and universal max-width rules JavaScript Height Detection: - Simplified from Math.max() with multiple properties to simple document.body.scrollHeight - This matches how the standard WebView gets height - Should resolve 'No valid JavaScript height found' errors The width overflow was caused by aggressive CSS rules that interfered with native layout. The height detection issue was likely due to complex JavaScript expressions not working with webPage.callJavaScript(). --- readeck/UI/Components/NativeWebView.swift | 59 +++++------------------ 1 file changed, 11 insertions(+), 48 deletions(-) diff --git a/readeck/UI/Components/NativeWebView.swift b/readeck/UI/Components/NativeWebView.swift index 8a8ebda..09e85f5 100644 --- a/readeck/UI/Components/NativeWebView.swift +++ b/readeck/UI/Components/NativeWebView.swift @@ -50,16 +50,8 @@ struct NativeWebView: View { try? await Task.sleep(nanoseconds: UInt64(delay * 1_000_000_000)) do { - // Try to get height via JavaScript - use direct expression instead of function call - let result = try await webPage.callJavaScript(""" - Math.max( - document.body.scrollHeight || 0, - document.body.offsetHeight || 0, - document.documentElement.clientHeight || 0, - document.documentElement.scrollHeight || 0, - document.documentElement.offsetHeight || 0 - ) - """) + // Try to get height via JavaScript - use simple document.body.scrollHeight + let result = try await webPage.callJavaScript("document.body.scrollHeight") if let height = result as? Double, height > 0 { let cgHeight = CGFloat(height) @@ -119,11 +111,6 @@ struct NativeWebView: View {