How can I open a specific link from browser in app?


#1

I am making a video conferencing app using Electron that is built off a browser-based app that does the same thing. I want to allow users to go through the typical user flow within the browser on the website, but once they get to the “join your video call” button, the Electron based app recommends to handle the request and open app to conduct the video call.

If anyone has experience doing such a thing (not so much the video conferencing aspect, but more allowing Electron to take control of specific links) I would love to see how you did it.

I have found the app.setAsDefaultProtocolClient but I am confused on how to use this. Would the protocol in my case here always be http and in which case, would my Electron app want to open every link from the browser? Or should I set the protocol to my-app-name and within the browser-based code, explicitly set the protocol to on the link to the same?


#2

No. Exactly the opposite. You want to pick something unique so that your system knows that your program is the only one that’s supposed to open that kind of URI. Don’t use http, https, or file, for sure, and you want to avoid ones like atom or torrent that might be used by another program.

Or should I set the protocol to my-app-name and within the browser-based code, explicitly set the protocol to on the link to the same?

Indeed.


#3

Great, thanks for the reply.

As far as how it should work I have in my initialize function:

app.setAsDefaultProtocolClient('my-app-name')
console.log(app.isDefaultProtocolClient('my-app-name')) // returns true

With that, should I explicitly be able to set links in my web based application like my-app-name://someurl.com? On top of that how does electron know? Does it set up a listener within the OS that directs mouse clicks if it matches the correct criteria?


#4

For any compatible operating system, Electron can tell the OS that URLs that follow a particular pattern (the protocol) should be opened in your application.