arielsalminen / feature.js

Feature.js is a fast, simple and lightweight browser feature detection library in 1kb.
https://featurejs.com/
3.17k stars 115 forks source link

ContextMenu false negative #6

Open theprojectsomething opened 8 years ago

theprojectsomething commented 8 years ago

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(); });

arielsalminen commented 8 years ago

@theprojectsomething Thanks for this!

meowsus commented 5 years ago

@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.