0

UPDATE: I have been able to get the website to redirect, but my electron app is not yet able to intercept that action. Is that possible in development? I have asked that question here.


I'm trying to register a custom protocol with electron. I want it to be a redirect location that a website can use to provide an api key (like myprotocol://example/payload=api-key).

But when the website tries to redirect to my protocol it keeps saying: failed to launch myprotocol://example/payload=key... because the scheme does not have a registered handler. What do I need to do to make this work?

I'm hoping to make this work in production and development.

I've seen discussion here and the comments here. Following along the docs from electron here, this is what I've tried:

main.js:

const { app, protocol } = require('electron')
    
app.whenReady().then(() => {
   protocol.registerFileProtocol('myprotocol', (request, callback) => {
      console.log('It worked! The website is sending this url: ' + request.url)
   }, (error) =>{
      if (error) console.log('Did not register the protocol')
   })
})

redirect uri provided to the website:

'myprotocol://example'

And I have been able to whitelist myprotocol://example at the website.

But, when the website tries to redirect to this protocol, my electron app does not register any activity, and the web inspector on the website shows the error: failed to launch myprotocol://example/payload=key... because the scheme does not have a registered handler.

I have additionally tried other methods, like registerSchemesAsPrivileged and registerHttpProtocol, without success.

Any ideas?

SeanRtS
  • 1,005
  • 1
  • 13
  • 31
  • Please make sure that your capitalisation is correct. You're registering `myprotocol` but are actually redirecting to `myProtocol`. I assume that this is case-sensitive and thus the capital `P` matters. – Alexander Leithner Jul 30 '21 at 13:09
  • capitalization for the protocol registered, redirected to, and whitelisted are the same. – SeanRtS Jul 30 '21 at 13:24
  • Maybe [this](https://stackoverflow.com/q/53530726/1244884) help (at least for the protocol bit?) – customcommander Jul 30 '21 at 15:26
  • Thanks. The answer you pointed to has some helpful ideas. It is focused on production, and I want something I can also work through in development. It also requires a few extra steps than the protocol API seems to require. So I am hoping there is a more direct solution. – SeanRtS Jul 30 '21 at 15:42

0 Answers0