WKWebView throws RBSServiceError when multiple SwiftUI views are created

Description

I've seen this issue when I use WKWebView in SwiftUI. If I have 2 web views at once in a SwiftUI view, it produces unwanted console warnings that seem to be not solvable on client side.

The warnings aren't present when there is only 1 web view.

Similar warnings regarding the "running board" or RBSAssertionErrorDomain are reported by others as well.

Please advice how to dismiss these warnings in the app. Thank you.

Repro Steps and Code

  1. Create a new iOS project.
  2. Put the following code into ContentView.swift. It wraps a WKWebView in SwiftUI and display some dummy html data in the web views.
  3. Build and run the app.
  4. Tap the info button.
  5. Drag down or dismiss the sheet. Upon dismiss, in the console it prints the error messages attached below.
import SwiftUI
import WebKit

struct ContentView: View {
    @State private var isInfoViewPresented = false
    
    @State private var selectedIndex = 0
    
    func makeErrorHTML(index: Int) -> String {
        #"<!doctype html><html><h1 style="text-align: center;">Unable to display README.</h1></html>"#
    }
    
    var body: some View {
        VStack(spacing: 8) {
            Text("Hello, world!")
            Button {
                isInfoViewPresented = true
            } label: {
                Image(systemName: "info.circle")
                    .imageScale(.large)
            }
            .sheet(isPresented: $isInfoViewPresented) {
                sheetContent
            }
        }
    }
    
    var sheetContent: some View {
        NavigationStack {
            ZStack {
                WebView(htmlString: makeErrorHTML(index: 0))
                    .background(Color(uiColor: .systemGray))
                    .opacity(selectedIndex == 0 ? 1 : 0)
                WebView(htmlString: makeErrorHTML(index: 1))
                    .background(Color(uiColor: .systemGray2))
                    .opacity(selectedIndex == 1 ? 1 : 0)
            }
            .toolbar {
                ToolbarItem(placement: .principal) {
                    Picker("Information Mode", selection: $selectedIndex) {
                        Text("0").tag(0)
                        Text("1").tag(1)
                    }
                    .pickerStyle(.segmented)
                }
                
                ToolbarItem(placement: .confirmationAction) {
                    Button("Done") {
                        isInfoViewPresented = false
                    }
                }
            }
        }
    }
}

struct WebView: UIViewRepresentable {
    /// The HTML to load in the web view.
    let htmlString: String
    
    func makeUIView(context: Context) -> WKWebView {
        // Creates an empty web view.
        let webView = WKWebView(frame: .zero)
        // Sets the web view's navigation delegate.
        webView.navigationDelegate = context.coordinator
        return webView
    }
    
    func updateUIView(_ webView: WKWebView, context: Context) {
        // Loads the given HTML string.
        webView.loadHTMLString(htmlString, baseURL: nil)
    }
    
    func makeCoordinator() -> Coordinator {
        Coordinator()
    }
    
    class Coordinator: NSObject, WKNavigationDelegate {
        func webView(
            _ webView: WKWebView,
            decidePolicyFor navigationAction: WKNavigationAction,
            decisionHandler: @escaping (WKNavigationActionPolicy) -> Void
        ) {
            switch navigationAction.navigationType {
            case .linkActivated:
                if let url = navigationAction.request.url, UIApplication.shared.canOpenURL(url) {
                    UIApplication.shared.open(url)
                }
                decisionHandler(.cancel)
            default:
                decisionHandler(.allow)
            }
        }
    }
}

OS Version

  • iOS 15 - iOS 17 Simulator and Device
  • Xcode Version 15.0.1 (15A507)
  • macOS 14.1.1 (23B81)

Similar Posts

Error From Console

Error acquiring assertion: <Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}>
0x11e024780 - ProcessAssertion::acquireSync Failed to acquire RBS assertion 'XPCConnectionTerminationWatchdog' for process with PID=85,796, error: Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}
Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}>
0x11e0247e0 - ProcessAssertion::acquireSync Failed to acquire RBS assertion 'WebProcess NearSuspended Assertion' for process with PID=85,796, error: Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}
Error acquiring assertion: <Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}>
0x11e0248a0 - ProcessAssertion::acquireSync Failed to acquire RBS assertion 'WebProcess NearSuspended Assertion' for process with PID=85,797, error: Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}
Answered by cht1995 in 780536022

FB13464160 Apple responded that this error is log noice, and will be removed in a future update.

The example code above shows our real workflow. It can be strip down to the version below.

Dismiss the sheet by dragging down the page.

import SwiftUI
import WebKit

struct ContentView: View {
    @State private var isInfoViewPresented = false
    
    var body: some View {
        Button { isInfoViewPresented = true } label: { Image(systemName: "info.circle") }
            .sheet(isPresented: $isInfoViewPresented) {
                ZStack {
                    WebView(htmlString: "Hello World")
                    WebView(htmlString: "Foo Bar")
                }
            }
    }
}

struct WebView: UIViewRepresentable {
    let htmlString: String
    
    func makeUIView(context: Context) -> WKWebView {
        return WKWebView(frame: .zero)
    }
    
    func updateUIView(_ webView: WKWebView, context: Context) {
        webView.loadHTMLString(htmlString, baseURL: nil)
    }
}
Accepted Answer

FB13464160 Apple responded that this error is log noice, and will be removed in a future update.

WKWebView throws RBSServiceError when multiple SwiftUI views are created
 
 
Q