If I open Chrome and type in my-app:// in the URL / search bar, and press enter, Chrome displays a dialog box that says "Open my-app? A website wants to open this application". I can click ok and my Electron app opens.
I have a React app and I want to add the same functionality, that programatically prompts the user to launch the application via an alert. I have tried adding window.open('my-app://', '_blank') which opens a dialog, but it is not the same as the other dialog and when I click ok, I am told by Chrome that is has blocked a pop-up, and the app does not open. I have also tried using window.location.href = 'my-app://', but it does not work. In the console I get the error: "Failed to launch 'my-app://' because the scheme does not have a registered handler."
How do I present the user with a prompt / alert that when ok is clicked will launch my app, just like it does when I enter my-app:// manually in to the browser?
Try document.location, this works for opening VS Code.
function openVSC() {
document.location = 'vscode://open?url=';
}
<button onClick="openVSC()">Open VS Code</button>