javascriptsafari-extensiondownload-managerbrowser-extension

Pass a download link from a web browser to a third-party application


I was wondering how is it possible to pass a download link from a web browser to a third-party application instead of letting the web browser downloading it directly. Of course a browser extension is required. But I'm asking for the way it's working. For example is it possible by using the command line? sockets? Or is there any better way to do that? What are the requirements in both application and extension side? Also I'm developing for Mac, so JavaScript ActiveX is not working here.

Regards


Solution

  • To intercept downloads in a Safari extension, in the main HTML file, you can register to receive beforeload events, and then call the preventDefault() method on the event to forbid the download if you want to handle it differently. Then you need some form of interprocess communication to forward the link to your application, one way could be to create a custom URL scheme that trigger your application, for instance call myapp:thelink instead of http://thelink, and have your application registered with the OS to handle the myapp: protocol...

    http://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/MessagesandProxies/MessagesandProxies.html#//apple_ref/doc/uid/TP40009977-CH14-SW9

    http://cocoadev.com/wiki/HowToRegisterURLHandler