0

CefSharp links that open specific application doesnt work

Im trying to make my winform web browser be able to open specific applications like on roblox or other websites that run specific application

Im new to programming so i have no idea how to do stuff like this,any help is appreciated

this is my code:

using CefSharp;
using CefSharp.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lunarium
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        private void txtUrl_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
                browser.Load(txtUrl.Text);
        }

        ChromiumWebBrowser browser;
        private void btnGo_Click(object sender, EventArgs e)
        {
            browser.Load(txtUrl.Text);
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            browser = new ChromiumWebBrowser(txtUrl.Text);
            browser.Dock = DockStyle.Fill;
            this.pContainer.Controls.Add(browser);
            browser.TitleChanged += Browser_TitleChanged;
        }
        public void favicon()
        {
            Uri url = new Uri("https://" + new Uri(browser.Address).Host + "/favicon.ico");
            try
            {
                Icon img = new Icon(new System.IO.MemoryStream(new
                WebClient().DownloadData(url)));
                this.Icon = img;
            }
            catch (Exception)
            {
                this.Icon = Properties.Resources.tempIcon;
                //change tempIcon to your desired icon, extension is .ico 
            }
        }
        private void Browser_TitleChanged(object sender, TitleChangedEventArgs e)
        {
            this.Invoke(new MethodInvoker(() =>
            {
                Text = e.Title;
                favicon();
            }));
        }
    }
}
vvl1m
  • 1
  • Do you mean open web pages / navigate to web sites, open Windows desktop apps outside of the browser, or run a Chrome extension? What is a specific example, an URL that you expect to open Roblox? Do you mean your `txtUrl_KeyPress` handler? – Dave S May 24 '23 at 17:10
  • i mean the popup thingy that asks you "Run [name] app?" – vvl1m May 24 '23 at 17:31
  • Do you mean a `mailto:` type link, but for Roblox instead of Mail, that runs a WIndows Roblox app outside of the browser? That must be set up first by the external app before it will work. Try the link in Google Chrome to make sure it is set up. – Dave S May 24 '23 at 17:36
  • yes, how would i set it up tho? – vvl1m May 24 '23 at 17:51
  • An app (not the browser) adds a set of registry keys to the Windows registry to map a prefix like `bun:` to a command line to run the `Bunny` app with command-line arguments telling it what to do : `c:\foo\bunny.exe -hop "easter-basket"` then when the browser sees an URL like `bun://easter-basket` it sees the registry entries and knows it launch the `bunny` app with the command line. – Dave S May 24 '23 at 17:56
  • oh i see, but how would i make my browser see the registry keys and open the app? – vvl1m May 24 '23 at 18:05
  • You could intercept the BeforeBrowse event, look for the Roblox URL prefix, read the prefix entries in HKEY_CLASSES_ROOT, then execute - https://stackoverflow.com/questions/258416/shellexecute-equivalent-in-net – Dave S May 24 '23 at 18:25
  • Another approach might be to add a custom scheme handler instead of intercepting BreforeBrowse - https://stackoverflow.com/questions/35965912/cefsharp-custom-schemehandler – Dave S May 24 '23 at 18:35
  • `OnBeforeBrowser` is the approach I recommend. You can typically defer to windows to load the url. See https://github.com/cefsharp/CefSharp/wiki/General-Usage#protocol-execution – amaitland May 27 '23 at 20:17

0 Answers0