简体   繁体   English

Firefox Quantum 获取 url (VB.Net/C#)

[英]Firefox Quantum get url (VB.Net/C#)

Anyone knows how to get the url from firefox quantum?任何人都知道如何从 Firefox 量子获取 url? I know for firefox:我知道火狐:

 Dim DdeClient As New DdeClient("Firefox", "WWW_GetWindowInfo")
 DdeClient.Connect()
 Dim URL As String = DdeClient.Request("URL", Integer.MaxValue)
 DdeClient.Disconnect()
 URL = Split(URL, """,""")(0)
 URL = Split(URL, """")(1)

Taking a look on this answer and considering the comment of Peter: it's working for me but it takes a while to get the url看看这个答案并考虑彼得的评论: it's working for me but it takes a while to get the url

I wrote the following code.我写了以下代码。 Maybe it could be helpful to someone:也许它可能对某人有帮助:

  Process[] lFFs = Process.GetProcessesByName("firefox");

                    for (int i = 0; i < lEs.Length; i++)
                    {
                        UIAutomationClient.IUIAutomationElement ee = lEs.GetElement(i);
                        if (ee != null && ee.CurrentName  != null &&
 (ee.CurrentName.Contains("search") || ee.CurrentName.Contains("navigation")))                       
    { // For spanish you can use: (ee.CurrentName.Contains("de búsqueda") || ee.CurrentName==  "Barra de navegación")

                            lEs = ee.FindAll(UIAutomationClient.TreeScope.TreeScope_Children, c);
                            if (lEs.Length > 0)
                                i = 0;
                            else
                            {
                                try
                                {
                                    object obj = ee.GetCurrentPattern(10002); // 10002: ValuePattern

                                    if (obj != null)
                                    {
                                        string sUrl = ((UIAutomationClient.IUIAutomationValuePattern)obj).CurrentValue;
                                        return  sUrl;
                                    }
                                }
                                catch
                                { }
                            }
                        }
                    }

Important , to make this code to work, your code must reference the COM library: UIAutomationClient重要的是,要使此代码工作,您的代码必须引用 COM 库:UIAutomationClient

I did it myself with this我用这个自己做的

        Dim ProcessFireFox As Process() = Process.GetProcessesByName("firefox")
        If ProcessFireFox.Count = 0 Then
            MsgBox("firefox not found", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Error")
            Exit Sub
        End If
        For Each Firefox As Process In ProcessFireFox
            If Firefox.MainWindowHandle = IntPtr.Zero Then Continue For
            Dim AutomationElement As System.Windows.Automation.AutomationElement = System.Windows.Automation.AutomationElement.FromHandle(Firefox.MainWindowHandle)
            For Each Elm As System.Windows.Automation.AutomationElement In AutomationElement.FindAll(TreeScope.Descendants, New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document))
                Dim BAutomationPattern As System.Windows.Automation.AutomationPattern() = Elm.GetSupportedPatterns()
                Dim BValuePattern As System.Windows.Automation.ValuePattern = DirectCast(Elm.GetCurrentPattern(BAutomationPattern(0)), System.Windows.Automation.ValuePattern)
                MsgBox(BValuePattern.Current.Value.ToString)
            Next
        Next

For me it helped disabling multi-process Firefox (Electrolysis/e10s).对我来说,它有助于禁用多进程 Firefox (Electrolysis/e10s)。

In version 57.0.4 goto about:config and set:在 57.0.4 版本中转到about:config并设置:

browser.tabs.remote.autostart=false (default)
browser.tabs.remote.autostart.2=false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM