Search code examples
wpfgeckogeckofx

Geckofx get loaded page url


I am using geckofx-22 in my WPF app. I want to check the current url of the page which is loaded in the geckofx control. Can't find any property for the same.


Solution

  • Use the below code for WPF and place it in Geckofx-WPF GeckoWebBrowser.cs

        /// <summary>
        /// Gets the <see cref="Url"/> currently displayed in the web browser.
        /// Use the <see cref="Navigate(string)"/> method to change the URL.
        /// </summary>
        [BrowsableAttribute(false)]
        public Uri Url
        {
            get
            {
                if (_webNav == null)
                    return null;
    
                nsIURI locationComObject = _webNav.GetCurrentURIAttribute();
                var uri = locationComObject.ToUri();
                Xpcom.FreeComObject(ref locationComObject);
                return uri ?? new Uri("about:blank");
            }
        }
    

    You can then access the url as

    geckoWebbrowser.Url;