Search code examples
c#cefsharp

How to Get the Current URL Adress From cef Browser c# winforms


How can i get The current Url from cef browser c# winforms . i want URL to be displayed in textBox1 in Form1 Whenver browser loads a URL ( visit a website )


Solution

  • To get the current URL from the CEF browser in a C# WinForms project, you need to add these things in your code:

    1. Create an Address Changed Event for the browser.

    2. Put this code in the:

      private void chromiumWebBrowser1_AddressChanged(object sender, AddressChangedEventArgs e)
      
      string url = e.Address;
      textBox1.Invoke(new Action(() => textBox1.Text = url));
      

    For Example:

    private void chromiumWebBrowser1_AddressChanged(object sender, AddressChangedEventArgs e)
    {
        string url = e.Address;
        textBox1.Invoke(new Action(() => textBox1.Text = url));
    }
    

    In the above example, we see that whenever the browser loads a URL, it triggers the address change event and, inside the event, we are getting the URL using the Invoke method.

    if any futher questions reply to this ANSWER

    Regards Adit