任何人都知道如何从firefox量程获取网址?我知道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)
答案 0 :(得分: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
答案 1 :(得分:0)
我自己用这个
做到了 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
答案 2 :(得分:0)
对我来说,这有助于禁用多进程Firefox(Electrolysis / e10s)。
在版本57.0.4中转到about:config
并设置:
browser.tabs.remote.autostart=false (default)
browser.tabs.remote.autostart.2=false