diff --git a/feature-detects/custom-protocol-handler.js b/feature-detects/custom-protocol-handler.js index 52bb2abb2e..9ef1499962 100644 --- a/feature-detects/custom-protocol-handler.js +++ b/feature-detects/custom-protocol-handler.js @@ -16,9 +16,25 @@ !*/ /* DOC -Detects support for the `window.registerProtocolHandler()` API to allow web sites to register themselves as possible handlers for particular protocols. +Detects support for the `window.registerProtocolHandler()` API to allow web +sites to register themselves as possible handlers for particular protocols. */ define(['Modernizr'], function( Modernizr ) { - Modernizr.addTest('customprotocolhandler', !!navigator.registerProtocolHandler); + Modernizr.addTest('customprotocolhandler', function() { + // early bailout where it doesn't exist at all + if ( !navigator.registerProtocolHandler ) return false; + + // registerProtocolHandler was stubbed in webkit for a while, and didn't + // actually do anything. We intentionally set it improperly to test for + // the proper sort of failure + try { + navigator.registerProtocolHandler('thisShouldFail'); + } + catch (e) { + return e instanceof TypeError; + } + + return false; + }); });