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?