custom-protocol-handler.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*!
  2. {
  3. "name": "Custom protocol handler",
  4. "property": "customprotocolhandler",
  5. "authors": ["Ben Schwarz"],
  6. "builderAliases": ["custom_protocol_handler"],
  7. "notes": [{
  8. "name": "WHATWG Spec",
  9. "href": "https://html.spec.whatwg.org/dev/system-state.html#custom-handlers"
  10. },{
  11. "name": "MDN Docs",
  12. "href": "https://developer.mozilla.org/en-US/docs/Web/API/navigator.registerProtocolHandler"
  13. }]
  14. }
  15. !*/
  16. /* DOC
  17. Detects support for the `window.registerProtocolHandler()` API to allow websites to register themselves as possible handlers for particular protocols.
  18. */
  19. define(['Modernizr'], function(Modernizr) {
  20. Modernizr.addTest('customprotocolhandler', function() {
  21. // early bailout where it doesn't exist at all
  22. if (!navigator.registerProtocolHandler) {
  23. return false;
  24. }
  25. // registerProtocolHandler was stubbed in webkit for a while, and didn't
  26. // actually do anything. We intentionally set it improperly to test for
  27. // the proper sort of failure
  28. try {
  29. navigator.registerProtocolHandler('thisShouldFail');
  30. }
  31. catch (e) {
  32. return e instanceof TypeError;
  33. }
  34. return false;
  35. });
  36. });