WebKit - WKWebView: How can I control maximumProcessCount of the processPool property?

Apple docs for WKWebView state: "The process pool associated with a web view is specified by its web view configuration. Each web view is given its own Web Content process until an implementation-defined process limit is reached; after that, web views with the same process pool end up sharing Web Content processes."


I can see something called maximumProcessCount for the processPool property when I NSLog the description for WKWebView, but I can't find any way to control the process limit, as described by Apple above.


I need to do this, because my (MacOS/Objective-C) app can have a large number of WKWebViews at times, and the huge number of processes spawned by all of them brings the system to its knees.


Thanks in advance for any help!

I can't find any way to control the process limit

Right. That’s what “implementation defined” means. If you had control, it’d be defined by you, not the implementation (-:

the huge number of processes spawned by all of them brings the system to its knees.

Oi vey!, that’s not good. Have you tried sharing a process pool between these web views? If you do that then the web views should end up using the same pool, and the pool’s limit will prevent excessive resource use.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

For context, I do a lot less web view support now than I did when you started this thread (-:

On the process pool front, you can allocate a WKProcessPool like you would any other object. You then tell the web view to use the pool by setting the processPool property on the WKWebViewConfiguration you use to create the web view.

Also, I'm kinda old-school, using Objective-C on macOS.

All of stuff is the same in Swift and Objective-C, and on iOS and macOS.

if you can help an OG Mac guy, that would be awesome.

Sure (speaking as an “OG Mac guy” myself).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

My instinct for creating a single shared processPool is to create a simple class as a singleton, with nothing in it but the processPool, and share that. Does this make sense, or is there a better (simpler?) way?

That’s a reasonable approach.

As to whether there’s a better way, it kinda depends on the dependency injection architecture for your app as a whole. If your app already has a dependency injection strategy, it would make sense to add this to that. If not, you might want to think about adopting one in the future, but I wouldn’t use this as the reason to do so.

I'm trying to add items to the contextual menu for the WKWebView. Can you offer any guidance on this?

iOS has the happy webView(_:contextMenuConfigurationForElement:completionHandler:) UI delegate callback, but that’s not support on macOS )-:

Beyond that, I don’t have any specific advice. Your question is about the ‘top half’ of the web view — the UI side of it rather than the networking side — and that’s never been my thing )-:

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

WebKit - WKWebView: How can I control maximumProcessCount of the processPool property?
 
 
Q