Using custom electron protocols in development

Viewed 343

I'm developing an Electron app that requires a custom protocol. I'd like to be able to test this in a development environment using the electron cli. I'm currently registering the protocol with:

const protocolRegisterSuccess = app.setAsDefaultProtocolClient('my-protocol');

I then start my development electron app with electron main.bundle.js and open my-protocol://test in Chrome. I would expect it to open my currently running development application or at least starting another one, however it starts a new electron app that shows the default electron screen ("To run a local app, execute this command...").

I'm developing on Mac and when I look in ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist I can see that the protocol is registered and the app id is set to com.github.electron. It looks like this is the app ID of the electron executable that is started by the electron CLI to run my app locally (existing in ./node_modules/electron/dist/Electron.app/Contents/MacOS/Electron) and I believe this is why the protocol is not working.

Is there any way to get the protocol working locally? Can I update the app identifier (via some config parameter or by rebuilding the executable)? Is it possible to specify the arguments passed to the executable that is started on Mac? I don't need the behavior to be exactly the same as a completely packaged app, but I'd like to be able to test basic custom protocols in development.

Thank you!

0 Answers
Related