Make WKWebView invisible or shrunken to just few points

I am interacting with javascript on an html web page with my swift code, but I don't need the actual html view. Is there a way to hide this from showing, but still have it in the render flow?

I cannot use JavaScriptCore because I need things like fetch and npm packages.

I tried WKWebView frame: .zero or CGRect all zero values but this did not work.

Just don't embed the WKWebView in the view hierarchy.

That didn't work as some func were not auto loading. I ended up giving it a frame of all 0.

I don't know what this means.

I also don't know what this means.

Methods like makeUIView and updateUIView don't get called unless its put into body property to be rendered.

So this is why you think the WKWebView needs to be in the view hierarchy to work. An instance of UIViewRepresentable does need to be in the view hierarchy in order for the makeUIView and updateUIView methods to be called, but you shouldn't be using UIViewRepresentable at all. It makes no sense to use UIViewRepresentable if you don't want the UIView it wraps to be in the view hierarchy.

Just create an instance of WKWebView directly in one of your model classes and perform whatever work you need with it.

Terms of Service

Privacy Policy

Cookie Policy