ios – WKWebView pixel width would not match Cell Safari


I’m simply beginning out with Swift making an attempt to wrap a webapp right into a single view utility to undergo the app retailer. I’m making a full display screen WkWebView. I’m testing on an iPad professional 12.9 inch. After I run the app, the WkWebView shows the content material as if the browser has a width of 1024px and a top of 768px. After I run the app as a progressive webapp or in cell safari, the app is displayed as if it has a width of 1366px and a top of 1024px (which is what I anticipated). How can I get the WKWebView to have the identical dimensions because the PWA and Cell Safari? In any other case, what am I lacking, why are the size completely different?

My code is displayed beneath:

index.html header incorporates:

<meta title="viewport" content material="width=device-width, top=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">


import SwiftUI
import WebKit

struct ContentView: View {
    non-public let urlString: String = ""

    var physique: some View {
        WebView(url: URL(string: urlString)!).background([.all]).statusBar(hidden: true)

class WebviewController: UIViewController, WKNavigationDelegate {

    var webview: WKWebView!
    var webViewURLObserver: NSKeyValueObservation?

    open override var preferredScreenEdgesDeferringSystemGestures: UIRectEdge {
       return [.all]

    override func viewDidLoad() {
        let config = WKWebViewConfiguration()
        let js = "window.isNativeApp=true;"
        let script = WKUserScript(supply: js, injectionTime: .atDocumentEnd, forMainFrameOnly: false)
        webview = WKWebView(body: self.view.body, configuration: config)

        self.webview.navigationDelegate = self
        self.webview.body = self.view.body

struct WebView: UIViewControllerRepresentable {
    let url: URL

    func makeUIViewController(context: Context) -> WebviewController {
        let webviewController = WebviewController()
        return webviewController

    func updateUIViewController(_ webviewController: WebviewController, context: Context) {
        let request = URLRequest(url: url)
        webviewController.webview.uiDelegate = context.coordinator
        webviewController.webview.navigationDelegate = context.coordinator
        webviewController.webview.scrollView.contentInsetAdjustmentBehavior = .by no means

    class Coordinator: NSObject, WKUIDelegate, WKNavigationDelegate  {
        var mother or father: WebView

        init(_ mother or father: WebView) {
            self.mother or father = mother or father

    func makeCoordinator() -> Coordinator {

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {

In javascript, doc.documentElement.clientWidth, window.innerWidth, and doc.physique.offsetWidth all give completely different values within the WKWebView iOS app when in comparison with Cell Safari or PWA.


Please enter your comment!
Please enter your name here