Home > Enterprise >  WKWebView ViewportSizing logs in SwiftUI
WKWebView ViewportSizing logs in SwiftUI

Time:08-16

In using SwiftUI, the WKWebView loads successfully when implemented within a UIViewRepresentable wrapper. However, the following logs appear in the Debug area of Xcode Version 13.4.1:

[ViewportSizing] maximumViewportInset cannot be larger than frame
[ViewportSizing] minimumViewportInset cannot be larger than frame

How can these logs be resolved?

These logs can be reproduced with the following minimal reproducible example:

WebApp.swift

import SwiftUI
import WebKit

@main
struct WebApp: App {
    var body: some Scene {
        WindowGroup {
            WebView()
        }
    }
}

struct WebView: UIViewRepresentable {
    func makeUIView(context: Context) -> some UIView {
        let webView = WKWebView()
        webView.load(URLRequest(url: URL(string: "https://www.google.com")!))
        
        return webView
    }
    
    func updateUIView(_ uiView: UIViewType, context: Context) {}
}

PROGRESS:

These logs seem to originate from the following WebKit browser engine source code:

These logs persist despite commenting out the webView.load(URLRequest(url: URL(string: "https://www.google.com")!)) line. So, it's concludable that it's not a website issue.

CodePudding user response:

This can be resolved by setting the frame to more than zero by changing this:

let webView = WKWebView()

To this:

let webView = WKWebView(frame: CGRect(x: 0.0, y: 0.0, width: 0.1, height: 0.1))
  • Related