feature.js icon indicating copy to clipboard operation
feature.js copied to clipboard

ContextMenu false negative

Open theprojectsomething opened this issue 9 years ago • 2 comments

The ContextMenu test requires both contextmenu and HTMLMenuItemElement to be present. As the latter is currently unsupported in everything but Gecko this test returns false across all other major browsers. More importantly contextmenu alone is enough to override a context menu (or 'right-click' as is mentioned on the test page).

Is HTMLMenuItemElement necessary, and if so should the test be split in two?

The following code suppresses a context menu on all modern browsers: document.addEventListener( "contextmenu", function(e) { e.preventDefault(); });

theprojectsomething avatar Jan 11 '16 00:01 theprojectsomething

@theprojectsomething Thanks for this!

arielsalminen avatar Jan 11 '16 15:01 arielsalminen

@viljamis I'm confused as to what we're actually trying to test with feature.contextMenu.

@theprojectsomething is right. This test fails almost entirely across the board, unless you're in a Gecko-based browser, like Firefox, but from what I can tell it's not due to the HTMLMenuItemElement portion of the test. Testing reveals that Chrome and Edge also return false on the ('contextMenu' in document.documentElement) portion of the test as well.

If we're trying to test for the support of the contextmenu event, I think that's a different test entirely. We could employ something like this for event-based detection.

I was a little surprised to see that Modernizr also constructs its test this way.

I'm soliciting feedback from the Modernizr community on this one.

meowsus avatar May 18 '19 18:05 meowsus