'Swift / Xcode: WebProcessProxy Invalid connection identifier (web process failed to launch)

I have a super simple Webview-loading tester app, but every time it tries to connect to the internet, the console shows:

WebProcessProxy::didFinishLaunching: Invalid connection identifier (web process failed to launch)

Here's the test app. This is all the custom code added after creating a blank SwiftUI app):

// ContentView.swift
import SwiftUI


struct ContentView: View {
  @State private var showWebView = false

  var body: some View {
    Button {
      showWebView.toggle()
    } label: {
      Text("Apple website")
    }
    .sheet(isPresented: $showWebView) {
      WebView(url: URL(string: "https://www.apple.com")!)
    }
  }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

// WebView.swift
import SwiftUI
import WebKit

struct WebView: NSViewRepresentable {
  
  var url: URL
  
  func makeNSView(context: Context) -> WKWebView {
    return WKWebView()
  }
  
  func updateNSView(_ webView: WKWebView, context: Context) {
    let request = URLRequest(url: url)
    webView.load(request)
  }
}

I've tried multiple WiFi connections so it's not something local.



Solution 1:[1]

Solved.

In Signing & Capabilities, in the App Sandbox section => Network, tick the checkbox next to "Outgoing Connections (Client)"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Will Taylor