Bug 244149 - REGRESSION (iOS 16): New context menu (UIEditMenuInteraction) can't be disabled
Summary: REGRESSION (iOS 16): New context menu (UIEditMenuInteraction) can't be disabled
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: UI Events (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Devin Rousso
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-08-19 17:15 PDT by Kurt Revis
Modified: 2023-08-28 10:50 PDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kurt Revis 2022-08-19 17:15:30 PDT
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?
Comment 1 Kurt Revis 2022-08-19 17:17:23 PDT
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.
Comment 2 Radar WebKit Bug Importer 2022-08-20 19:00:50 PDT
<rdar://problem/98935540>
Comment 3 Devin Rousso 2022-08-23 10:51:17 PDT
@Kurt Revis, I'm told that maybe overriding `-buildMenuWithBuilder:` would allow you to control this.  Could you give that a try?
Comment 4 Kurt Revis 2022-08-23 11:54:56 PDT
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.)
Comment 5 Devin Rousso 2022-09-29 17:32:17 PDT
Pull request: https://github.com/WebKit/WebKit/pull/4845
Comment 6 EWS 2022-10-05 14:23:11 PDT
Committed 255193@main (9ce57ec0f4b3): <https://commits.webkit.org/255193@main>

Reviewed commits have been landed. Closing PR #4845 and removing active labels.