Bug 244149
| Summary: | REGRESSION (iOS 16): New context menu (UIEditMenuInteraction) can't be disabled | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Kurt Revis <krevis> |
| Component: | UI Events | Assignee: | Devin Rousso <hi> |
| Status: | RESOLVED FIXED | ||
| Severity: | Normal | CC: | hi, webkit-bug-importer, wenson_hsieh |
| Priority: | P2 | Keywords: | InRadar |
| Version: | Other | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
| See Also: | https://bugs.webkit.org/show_bug.cgi?id=260722 | ||
Kurt Revis
In iPadOS 16 beta 6, WKWebView shows the system edit menu (via UIEditMenuInteraction) when you control-click or right-click or two-finger-click anywhere in the web view.
We have our own handling of these events, so we don't want that menu, but there appears to be no way to disable it, or customize it.
- Tried catching the `contextmenu` event and calling `preventDefault`, as shown in the example in the MDN docs: https://developer.mozilla.org/en-US/docs/Web/API/Element/contextmenu_event
Example: https://codepen.io/krevis-figma/pen/yLKejBa
This doesn't work. The handler fires but `preventDefault()` has no effect.
- Looked for relevant delegate methods, but there aren't any.
The closest thing is these WKUIDelegate methods to be called when the menu appears and disappears, but that's all:
https://bugs.webkit.org/show_bug.cgi?id=243102
Those would only let us add animations alongside the menu, anyway. They wouldn't let us disable the menu or customize its items.
- Looked for any UIKit API to globally disable the new edit menu, but there's nothing.
Could we please have a way to disable this thing? Ideally via calling `preventDefault()` on the `contextmenu` event?
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Kurt Revis
Even worse, showing and dismissing this menu causes the trackpad/mouse to stop sending `pointerdown` events, as in https://bugs.webkit.org/show_bug.cgi?id=236390.
Radar WebKit Bug Importer
<rdar://problem/98935540>
Devin Rousso
@Kurt Revis, I'm told that maybe overriding `-buildMenuWithBuilder:` would allow you to control this. Could you give that a try?
Kurt Revis
That solution wouldn't help pure web content. In Safari on MacOS, preventDefault() stops the system context menu from appearing. That should also work on iPadOS.
I can override -buildMenuWithBuilder: on a subclass of WKWebView, and it is called. But if I do nothing and don't call super, the menu still appears, with a few items (Copy, Select all, Translate, Share). We don't want the menu to appear at all.
UIMenuBuilder does not provide a way to determine what items are actually in the menu so far, but I can just blindly guess, and remove the ones I think might be there. That's a pretty fragile workaround, though.
(If I do succeed in removing all the items, then nothing appears, and the pointer-event bug is not triggered. So that's good, at least.)
Devin Rousso
Pull request: https://github.com/WebKit/WebKit/pull/4845
EWS
Committed 255193@main (9ce57ec0f4b3): <https://commits.webkit.org/255193@main>
Reviewed commits have been landed. Closing PR #4845 and removing active labels.