【问题标题】:Firefox Quantum get url (VB.Net/C#)Firefox Quantum 获取 url (VB.Net/C#)
【发布时间】:2018-01-24 04:10:56
【问题描述】:

有人知道如何从 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)

【问题讨论】:

    标签: c# vb.net firefox


    【解决方案1】:

    看看这个answer 并考虑彼得的评论: it's working for me but it takes a while to get the url

    我写了以下代码。也许对某人有帮助:

      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
                                    { }
                                }
                            }
                        }
    

    重要,要使此代码正常工作,您的代码必须引用 COM 库:UIAutomationClient

    【讨论】:

      【解决方案2】:

      这是我自己做的

              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
      

      【讨论】:

      • 您好,您的代码还在工作吗?我确实尝试过,但没有成功。 @PeterJ
      • 它对我有用,但获取网址需要一段时间
      【解决方案3】:

      对我来说,它有助于禁用多进程 Firefox(电解/e10s)。

      在版本 57.0.4 中转到 about:config 并设置:

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

      【讨论】:

        猜你喜欢
        • 2018-06-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-01
        • 2018-05-06
        • 1970-01-01
        相关资源
        最近更新 更多