In 18.2 beta, WKWebView consumes `buildMenu`

I have a view controller that is hosing a WKWebView. My view controller overrides buildMenu(with builder: UIMenuBuilder), and prior to the beta, this was called reliably. However under 18.2 beta 4, it is not called at all, despite no code changes on my part.

Things I've tried:

  • Ensured that my responder chain is set up correctly.
  • Walked through the debugger via a symbolic breakpoint on [UIResponder buildMenuWithBuilder:] to understand that the web view is the last object to get a buildMenuWithBuilder message.

Any feedback or commiseration would be appreciated.

Answered by elementarteilchen in 816878022

I can experience the same issue and this bug breaks some features of my App as well.

But I’ve found some kind of workaround: If you overide WKWebView you can override buildMenu(with builder: UIMenuBuilder) there. Within this method you first call super.buildMenu(with builder: UIMenuBuilder) to let the webview do its menu configuration and then you can do your own menu configuration (for example adding your own menu items).

This might not be the most elegant solution, but at least for my project it is an easy workaround and works well.

Could you please file a feedback report and include a sample project with a WKWebView and your buildMenuWithBuilder not being called? This will really help with investigating this issue. Thanks!

Accepted Answer

I can experience the same issue and this bug breaks some features of my App as well.

But I’ve found some kind of workaround: If you overide WKWebView you can override buildMenu(with builder: UIMenuBuilder) there. Within this method you first call super.buildMenu(with builder: UIMenuBuilder) to let the webview do its menu configuration and then you can do your own menu configuration (for example adding your own menu items).

This might not be the most elegant solution, but at least for my project it is an easy workaround and works well.

I ended up using the same approach as @elementarteilchen, gating with an availability check on 18.2. I came back to post it, and @elementarteilchen had already discovered it. Glad to see it wasn't just me.

In 18.2 beta, WKWebView consumes `buildMenu`
 
 
Q