WKWebView: loadHTMLString and createPDF always fails since updating to macOS Monterey

Hello,

I had programmed and used a software for a year without problems but after updating to Monterey and updating XCode, the following, simplified Playground example of the process always fails and I cannot figure out why. Please note this project is specifically written for macOS and I cannot use the iOS libraries for PDF generation.

import WebKit
import PDFKit
import SwiftUI
import CoreGraphics

let webView: WKWebView = WKWebView(frame: CGRect(x: 0, y: 0, width: 595.0, height: 842.0), configuration: WKWebViewConfiguration())
let htmlString = "<html><body><h1>Hello</h1></body></html>"
webView.loadHTMLString(htmlString, baseURL: nil)
webView.createPDF(completionHandler: compHandler)

func compHandler(res: Result<Data, Error>) -> Void {
    print(res)
}

This always results in an error:

failure(Error Domain=WKErrorDomain Code=1 "An unknown error occurred" UserInfo={NSLocalizedDescription=An unknown error occurred})

I cannot find anything in the documentation regarding this and most examples and questions are old and not applicable (many still using Objective-C).

Debugging seems to suggest that the loadHTMLString itself fails, not even necessarily the PDF itself.

Any pointers would be appreciated.

Thanks

WKWebView: loadHTMLString and createPDF always fails since updating to macOS Monterey
 
 
Q