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!

Replies

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"
  • Hi Quinn,

    It's only been three years since my original question - apologies. (It's the pandemic's fault.)

    I'm revisiting this issue, and looking at your original response, you said "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."

    Can you offer any guidance as to how to do what you suggest? I have no idea how to share a process pool.

    I'm also trying an alternative solution: I'm using a singleton for the WKWebView, and that works, but I need to change where the WKWebView is seen, without modifying its content - kinda like changing its superview. That's not quite working, but I don't know if that's because it's impossible, or I'm just not doing it correctly yet.

    Also, I'm kinda old-school, using Objective-C on MacOS. I'm willing to try struggling with Swift, but if you can help an OG Mac guy, that would be awesome.

    Thanks...

    HS

Add a Comment

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"

  • Hi Quinn,

    This is really helpful - THANKS!

    I'm working on your suggestion for using a single processPool, shared amongst Many WKWebViews. It's getting there, but I have some related questions:

    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?I'm trying to add items to the contextual menu for the WKWebView. Can you offer any guidance on this? I was able to do this in WebView, but I don't see how to do it in WKWebView.

    For clarity, I'm using the WKWebView to display some live web content in one part of a splitView, but I want the user to NOT be able to interact with that content (other than scrolling it, and maybe going back or reloading via default contextual menu items - there's no navigation UI).

    Again, many thanks for your first response, and if you can help further, you'll make an aging coder very happy.

    Cheers,

    HS

Add a Comment

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"