Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: API for registering node-webkit applications as protocol handlers [$50] #951

Open
Mithgol opened this issue Aug 6, 2013 · 45 comments
Labels
bounty Electron Parity Adding a feature to NW.js that already or previously existed in Electron feature-request

Comments

@Mithgol
Copy link
Contributor

Mithgol commented Aug 6, 2013

Something like navigator.registerProtocolHandler(), but for node-webkit's applications.

The expected result is that the application is registered as a system-wide handler for the given protocol, i.e. is launched from the command line by the following:

  • on Mac: open protocol://...
  • on Windows: start "" protocol://...
  • on Linux: xdg-open protocol://...

Bonus feature request: an API to check if an application is already registered as a handler for the given protocol.

There is a $50 open bounty on this issue. Add to the bounty at Bountysource.

@morsdyce
Copy link

morsdyce commented Aug 7, 2013

+1 I would very much like that feature as well.

@ajmas
Copy link

ajmas commented Aug 9, 2013

For MacOS X you can already do this, statically, just modifying the info.plist in your customised node-webkit app:

http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html

The page describes the iPhone, but this works on the Mac as well. For an example, take a look at /Applications/Utilities/Terminal.app/Contents/Info.plist

Is this an acceptable solution on the Mac side? Do we need something more dynamic? Does anyone know if other operating system offer an equivalent approach?

Just did a bit more reading:

@morsdyce
Copy link

I think this way passing data to your application won't be possible without node-webkit changes to accept them and forward them to your application which is the true power of those urls

@sindresorhus
Copy link

👍

@ajmas
Copy link

ajmas commented Aug 16, 2013

For the moment a solution could be provided to people who want to take node-webkit and 'rebrand' for easier distribution of their solution. I am going to explain this from a Mac perspective, since that's what I have in front of me, in terms of documentation:

  • adding the registration statically in the configuration file of node-webkit (info.plist)
  • add a bridge between handleOpenURL() and an equivalent event on the JS side, such that in your document you would listen for systemEvents.onHandleOpenURL(...) or something?

At the very least this would offer a prototype for future work? It may be worth starting this as a general node package module and then making a node-webkit specific version once the other issues have been worked out?

@perqa
Copy link

perqa commented Oct 22, 2013

This sounds very interesting and useful, but as some of you already pointed out, you want to be able to pass in variables in those URLs. Has anything more happened since this thread was last active?

@verysimplenick
Copy link

protocol handlers very very useful in html5 apps. I want this feature

@shokurov
Copy link

shokurov commented Apr 5, 2014

This can be done with the following in /src/browser/app_controller_mac.mm

-(void)applicationWillFinishLaunching:(NSNotification *)aNotification
{
    NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
    [appleEventManager setEventHandler:self
                           andSelector:@selector(handleGetURLEvent:withReplyEvent:)
                         forEventClass:kInternetEventClass andEventID:kAEGetURL];
}

- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
  NSString *url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];

  if (content::Shell::windows().size() == 0) {
    CommandLine::ForCurrentProcess()->AppendArg([url UTF8String]);
    CommandLine::ForCurrentProcess()->FixOrigArgv4Finder([url UTF8String]);
    return;
  }

  // Just pick a shell and get its package.
  nw::Package* package = content::Shell::windows()[0]->GetPackage();

  if (package->self_extract()) {
    // Let the app deal with the opening event if it's a standalone app.
    nwapi::App::EmitOpenEvent([url UTF8String]);
  } else {
    // Or open a new app in the runtime mode.
  }
}

@jessep
Copy link

jessep commented Jun 5, 2014

👍

@gpetrov
Copy link

gpetrov commented Jun 28, 2014

@shokurov why don't you make a pull request our of this?

@fish520
Copy link

fish520 commented Jun 30, 2014

If only I can redirect a path request to a DB query that returns something, with a protocol handler
that accept a function, which return the content directly, without a server, in that case I can store the
most commonly used script files into a sqlite DB file, and share between diffrent applications... there's
more goods than I can imagine, see we are developing something like a software distribution platform,
etc.

@shokurov
Copy link

Sorry guys, have no time to make a pull request, please do whomever has a minute

@flippyhead
Copy link

👍

@tartavull
Copy link

+1 Great feature

@asinverse
Copy link

+1

@monorigabor
Copy link

+1 this would be very useful!

shokurov added a commit to shokurov/node-webkit that referenced this issue Oct 7, 2014
This is default OSX way of registering protocol handlers implemented
@shokurov
Copy link

shokurov commented Oct 7, 2014

Mac solution is posted as pull request #2429

@monorigabor
Copy link

@shokurov that's great news! Thanks a lot for it!

@rogerwang rogerwang changed the title Feature request: API for registering node-webkit applications as protocol handlers Feature request: API for registering node-webkit applications as protocol handlers [$50] Oct 16, 2014
@jwerle
Copy link

jwerle commented Oct 28, 2014

+1 very much needed !

@gyzerok
Copy link

gyzerok commented Dec 1, 2014

@rogerwang is there any information about release date for this feature?

@gpetrov
Copy link

gpetrov commented Dec 1, 2014

@rogerwang there is already a pull request for it, you just need to accept it: #1769

we really need this

@auchenberg
Copy link

Any update on this one?

@shainegordon
Copy link

is this supposed to be in v0.12.0-alpha3?

I just tested on mac, and it still seems that gui.App.argv is not populated, unlike on windows, where this works correctly

@ekhaled
Copy link

ekhaled commented Mar 12, 2015

This feature seems to have been nuked :(
See: #1769 (comment)

@sashahilton00
Copy link

bumping

@baconbrad
Copy link

Seeing how this is possible with an NPM it isn't too crazy to think someone can create a cross platform version of this NPM package. Of course I would drop edge.js and use a better method of accessing the registry to avoid needing the .NET framework.

@Mithgol
Copy link
Contributor Author

Mithgol commented May 15, 2015

Then, I guess, I'll close this issue when someone creates such a package.

@baconbrad
Copy link

It would be a nice feature to have. Doing a quick look on Linux and Mac instructions it seems it would only be a matter of creating or packaging some files with your app/protocol info and possibly doing some shell commands to put them in their proper places.

I don't have the time/need to make this so I am going to post the ingredients here:
Windows: http://stackoverflow.com/questions/389204/how-do-i-create-my-own-url-protocol-e-g-so
Mac: http://stackoverflow.com/questions/471581/how-to-map-a-custom-protocol-to-an-application-on-the-mac
Linux: http://superuser.com/questions/162092/how-can-i-register-a-custom-protocol-with-xdg

@alxlu
Copy link

alxlu commented May 17, 2015

This feature seems to have been nuked :(
See: #1769 (comment)

What is the latest version that still has support for this?

@hesmer-ibm
Copy link

I would love to have this as well. Any chance to get this in a future version ?

@achwedyk
Copy link

achwedyk commented Aug 6, 2015

What is the latest version that still has support for this?

I've tested various versions from http://dl.nwjs.io/. These were: 0.11.6, 0.11.7-rc1, 0.11.7-rc2, 0.12.0-alpha3 and 0.12.0-rc1 - none of them had this functionality working.

@renarsvilnis
Copy link

I think it's more of a build tool / packager issue. Each build tool does these processes different.

Experiment
Just took nw-boilerplate and added CFBundleURLTypes key to the nw-boilerplate/blob/master/resources/osx/Info.plist file as described in baconface #102505353 comment url for adding custom protocols for mac. Compiled the app for Mac and it worked. Safari redirected to my app.

Further
As i use nw-builder for building my nw apps, thinking of making a pull request of integrating this as a passable option. For now only for Mac.

Windows
Need to look into how to add registry keys within .nsi files. Something like this

Issues
But if we are binding custom protocols, we should unbind them when uninstalling the app or update them when updating the app.

Just deleted my previously compiled and installed app. Still have the protocol bindings in OS, although the behaviour is the same as before adding the custom protocol. Should look into whether how to remove them.

Note: used this to check protocols
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -dump|egrep "(bindings.*\:$)"|sort

@achwedyk
Copy link

@renarsvilnis you say

Compiled the app for Mac and it worked. Safari redirected to my app.

But the real problem on Mac is that currently there is no way for nw.js app to differentiate between myprotocol://do-a and myprotocol://do-b. Arguments are not passed to the application which in my opinion makes using protocol handlers on Mac almost useless.
That's why it would be good to have #1769 re-merged.
I've tested recently that it works with nw12 branch with this small change: achwedyk@6f3ba7c

@jaruba
Copy link

jaruba commented Aug 12, 2015

@achwedyk

Could you please upload the binary with the fix on a new repo and give a link?

You would save me (at least) a headache..

@achwedyk
Copy link

@jaruba I've done exactly as you've suggested. Here is the repo: https://github.com/achwedyk/nw.js-release
Note that I was building nw.js for the first time. But it compiled fine and initial tests went OK.

@jaruba
Copy link

jaruba commented Aug 13, 2015

@achwedyk Awesome! One question though, why did you build it for 32bit? It would of been safe (and recommended) to build it for 64bit architecture as all OSX are 64bit anyway. :)

@imeetdevpgi
Copy link

It's nice feature to open application from external source on Mac such as browser. Could you please provide us on which version of node-webkit, we can use this feature on windows?

@shainegordon
Copy link

this already works on windows with all versions of nw-js.

This requires windows registry entries, and has nothing to do with nw.js

here is an extract from my wix installer configuration

               <Component Id="RegistryEntries" Guid="206C911C-56EF-44B8-9257-5FD242127965">
                   <RegistryKey Root="HKCR"
                         Key="[protocol]"
                         Action="createAndRemoveOnUninstall">
                     <RegistryValue Type="string" Name="URL Protocol" Value=""/>
                     <RegistryValue Type="string" Value="URL:Project Name"/>
                     <RegistryValue Type="string" Name="Content Type" Value="application/x-[protocol]"/>
                     <RegistryKey Key="DefaultIcon">
                       <RegistryValue Type="string" Value="&quot;[INSTALLDIR]Executable.exe&quot;,1" />
                     </RegistryKey>
                     <RegistryKey Key="shell">
                        <RegistryValue Type="string" Value="open"/>
                     </RegistryKey>
                     <RegistryKey Key="shell\open\command">
                       <RegistryValue Type="string" Value="&quot;[INSTALLDIR]Executable.exe&quot; &quot;%1&quot;" />
                     </RegistryKey>
                   </RegistryKey>
                 </Component>

@snehapshinde
Copy link

Anybody still working on this issue(specially for Mac)?

@Mithgol
Copy link
Contributor Author

Mithgol commented Sep 27, 2016

These two months of silence are most likely to say “nope”.

@gpetrov
Copy link

gpetrov commented Sep 27, 2016

actually this is already implemented some time ago, for usage see: #4240 (comment)

maybe somebody should document it

@IssueHuntBot
Copy link

@rororofff has funded $2.00 to this issue.


@thiago4455
Copy link

This feature already works on all platforms.

On Linux, just set up your .desktop file:

  • Add %u at the end of the Exec line to pass the URL as an argument to your application:
Exec=your-app-location/nw %u
  • At the end of your .desktop file add (replacing your-protocol-name by your protocol):
MimeType=x-scheme-handler/your-protocol-name;

You can now access the URL with:

console.log(nw.App.argv);

I'd like to write proper documentation in Users/Advanced/, what do you think?

@TheJaredWilcurt
Copy link
Member

TheJaredWilcurt commented Aug 29, 2020

It would be nice if this could all be handled in an easy to use Node module with a simple API. I've created a repo with some documentation on the existing suggested solutions.

This can be a place to submit PR's against for each OS.

I need help from others though to get the library working. This is a very low priority for me, as I don't have a need for this functionality in my apps. But happy to maintain the library, merge PR's, test the functionality, and do releases.

@TheJaredWilcurt TheJaredWilcurt added the Electron Parity Adding a feature to NW.js that already or previously existed in Electron label Aug 29, 2020
@Shubham-Kumar-2000
Copy link

Shubham-Kumar-2000 commented Aug 21, 2021

Now There is a nm module to do this which supports macOS, windows and Linux as of now.
It can be done by just a function call.

const path = require('path');

const ProtocolRegistry = require('protocol-registry');

console.log('Registering...');
// Registers the Protocol
ProtocolRegistry.register({
    protocol: 'testproto', // sets protocol for your command , testproto://**
    command: `node ${path.join(__dirname, './index.js')} $_URL_`, // this will be executed with a extra argument %url from which it was initiated
    override: true, // Use this with caution as it will destroy all previous Registrations on this protocol
    terminal: true, // Use this to run your command inside a terminal
    script: false
}).then(async () => {
    console.log('Successfully registered');
});

You can read more about it here : https://www.npmjs.com/package/protocol-registry

This module is not exactly related to nwjs but you can achieve similar results with this workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bounty Electron Parity Adding a feature to NW.js that already or previously existed in Electron feature-request
Projects
None yet
Development

No branches or pull requests