Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect browser's protocol handlers?

I have created a custom URL protocol handler.

http://

mailto://

custom://

I have registered a WinForms application to respond accordingly. This all works great.

But I would like to be able to gracefully handle the case where the user doesn't have the custom URL protocol handler installed, yet.

In order to be able to do this I need to be able to detect the browser's registered protocol handlers, I would assume from JavaScript. But I have been unable to find a way to poll for the information. I am hoping to find a solution to this problem.

Thanks for any ideas you might be able to share.

like image 481
Chris Craft Avatar asked May 07 '09 20:05

Chris Craft


People also ask

What are protocol handlers?

A protocol handler is an application that knows how to handle particular types of links: for example, a mail client is a protocol handler for "mailto:" links.

What are URL handlers?

The URL Handler is a Sling Model and can be adapted either from a request or a resource. It automatically reads the context-specific configuration for the Site URLs based on the resource path of the current request or the path of the resource adapted from. Example: UrlHandler urlHandler = request.


4 Answers

This would be a very, very hacky way to do this... but would this work?

  • Put the link in as normal...
  • But attach an onclick handler to it, that sets a timer and adds an onblur handler for the window
  • (in theory) if the browser handles the link (application X) will load stealing the focus from the window...
  • If the onblur event fires, clear the timer...
  • Otherwise in 3-5seconds let your timeout fire... and notify the user "Hmm, looks like you don't have the Mega Uber Cool Application installed... would you like to install it now? (Ok) (Cancel)"

Far from bulletproof... but it might help?

like image 78
scunliffe Avatar answered Sep 20 '22 20:09

scunliffe


There's no great cross-browser way to do this. In IE10+ on Win8+, a new msLaunchUri api enables you to launch a protocol, like so:

navigator.msLaunchUri('skype:123456',    function()    {      alert('success');   },    function()   {     alert('failed');   }  );  

If the protocol is not installed, the failure callback will fire. Otherwise, the protocol will launch and the success callback will fire.

I discuss this topic a bit further here: https://web.archive.org/web/20180308105244/https://blogs.msdn.microsoft.com/ieinternals/2011/07/13/understanding-protocols/

This topic is of recent (2021) interest; see https://github.com/fingerprintjs/external-protocol-flooding for discussion.

like image 43
EricLaw Avatar answered Sep 17 '22 20:09

EricLaw


HTML5 defines Custom scheme and content handlers (to my knowledge Firefox is the only implementor so far), but unfortunately there is currently no way to check if a handler already exists—it has been proposed, but there was no follow-up. This seems like a critical feature to use custom handlers effectively and we as developers should bring attention to this issue in order to get it implemented.

like image 39
Hugh Guiney Avatar answered Sep 18 '22 20:09

Hugh Guiney


There seems to be no straightforward way via javascript to detect the presence of an installed app that has registered a protocol handler.

In the iTunes model, Apple provides urls to their servers, which then provide pages that run some javascript:

http://ax.itunes.apple.com/detection/itmsCheck.js

So the iTunes installer apparently deploys plugins for the major browsers, whose presence can then be detected.

If your plugin is installed, then you can be reasonably sure that redirecting to your app-specific url will succeed.

like image 45
jtomson Avatar answered Sep 19 '22 20:09

jtomson