From ad6ab10114d05bb2ade8b2c3ff4a0234db5563ac Mon Sep 17 00:00:00 2001 From: Patrick Kettner Date: Sun, 14 Jul 2013 22:32:18 -0400 Subject: [PATCH] improve custom-protocol-handler.js As documented in the Undetectables - https://github.com/Modernizr/Modernizr/wiki/Undetectables - navigator.registerProtocolHandler was stubbed in webkit for a while, and doesn't actually do anything there. This test forces a failure and ensures it's the right type of failure. --- feature-detects/custom-protocol-handler.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) 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; + }); });