Don't understand how to access heavyweight WKWebView from NSViewRepresentable

I create @State holding a WKWebView (heavyweight object), and then wrap that in a VKViewRepresentable, then

@State var myWebView = newWebView(request: URLRequest(url:URL(string: request)!))

This is the only way I can then reference the webView late on to run javascript queries on it. Otherwise, it's embedded in the View/ContentView hierarchy.

So then when I moved from Window to WindowGroup, only one of these WKWebView is created. This looks bad to have an empty detail panel in the previous Window. The docs on WindowGroup state that it makes new state to go with each Window in the WindowGroup, but in this case, that's not the case here.

Workaround for now is to make the app single-windowed with Window. Also openURL when using WindowGroup just makes a new Window when I really don't want it to.

Don't understand how to access heavyweight WKWebView from NSViewRepresentable
 
 
Q