X
點擊此處開啟此網站的行動版。

技術支援討論區

Read all opened URLs in all tabs

已張貼

Hello all. I want to read all opened URLs in all tabs from my own program on .NET Framework. How it is possible to do?

I try to use System.Windows.Automation, but this is extremely unstable way. A;so try to use Selenium. Its good choice, but firstly need to start FF under geckodriver and .NET wrapper about geckodriver - FirefoxDriver.

At common, when I doing something in my job, I have a lot, a lot of tabs. On the evening I leave computer and want to continue from this point on next morning or maybe after week. I want to save all opened URLa to my program, named this point with friendly name and return to this point in a few days. And in my program I want to have a history of this saving, arrange by date. But I have no idea about reliable and safe method of reading all opened URLs.

Hello all. I want to read all opened URLs in all tabs from my own program on .NET Framework. How it is possible to do? I try to use System.Windows.Automation, but this is extremely unstable way. A;so try to use Selenium. Its good choice, but firstly need to start FF under geckodriver and .NET wrapper about geckodriver - FirefoxDriver. At common, when I doing something in my job, I have a lot, a lot of tabs. On the evening I leave computer and want to continue from this point on next morning or maybe after week. I want to save all opened URLa to my program, named this point with friendly name and return to this point in a few days. And in my program I want to have a history of this saving, arrange by date. But I have no idea about reliable and safe method of reading all opened URLs.

被選擇的解決方法

I don't think Firefox exposes tab URLs externally. The active tab title is certainly exposed to Windows, but beyond that ???

Can you re-use the same profile and restore your previous session windows and tabs or do you always start with a clean profile?

There probably are extensions that can export a list of open tab URLs to a file in a format you can use, such as JSON or CSV. However, I haven't used any of those myself.

In case it might help, these are the session management extensions I'm aware of that you might investigate/try out:

Use database storage, not easy to use externally or across profiles:

Use bookmark storage, could export in a standard format:

從原來的回覆中察看解決方案 1
引用
jscher2000
  • Top 10 Contributor
8799 個解決方法 71970 個答案

選擇的解決方法

I don't think Firefox exposes tab URLs externally. The active tab title is certainly exposed to Windows, but beyond that ???

Can you re-use the same profile and restore your previous session windows and tabs or do you always start with a clean profile?

There probably are extensions that can export a list of open tab URLs to a file in a format you can use, such as JSON or CSV. However, I haven't used any of those myself.

In case it might help, these are the session management extensions I'm aware of that you might investigate/try out:

Use database storage, not easy to use externally or across profiles:

Use bookmark storage, could export in a standard format:

I don't think Firefox exposes tab URLs externally. The active tab title is certainly exposed to Windows, but beyond that ??? Can you re-use the same profile and restore your previous session windows and tabs or do you always start with a clean profile? There probably are extensions that can export a list of open tab URLs to a file in a format you can use, such as JSON or CSV. However, I haven't used any of those myself. In case it might help, these are the session management extensions I'm aware of that you might investigate/try out: ''Use database storage, not easy to use externally or across profiles:'' * https://addons.mozilla.org/firefox/addon/tab-session-manager/ * https://addons.mozilla.org/firefox/addon/session-boss/ ''Use bookmark storage, could export in a standard format:'' * https://addons.mozilla.org/firefox/addon/session-sync/ * https://addons.mozilla.org/firefox/addon/my-sessions/
這篇文章有幫助嗎? 1
引用
cor-el
  • Top 10 Contributor
  • Moderator
17588 個解決方法 159105 個答案

有幫助的回覆

You can possibly use code in the Browser Console to get the current session state including Private Browsing mode tabs/windows.

  • [/questions/1268444 how to recover unresponsive Pravaite Tabs on Linux
You can possibly use code in the Browser Console to get the current session state including Private Browsing mode tabs/windows. *[/questions/1268444 how to recover unresponsive Pravaite Tabs on Linux
這篇文章有幫助嗎? 1
引用

提出問題者

jscher2000 said

I don't think Firefox exposes tab URLs externally.

Thank you, jscher2000, for your answer, but FireFox certainly exposed opened table externally in many-many ways. There is a my simplest test and a result on the screen. But hierarchy of control not always equal, sometimes FF Tabs is placed deeper in hierarhy of automation control. And I don't see a google sometimes.

Module Module1

   Sub Main()
       Dim Firefox As Process() = Process.GetProcessesByName("firefox")
       If Firefox.Length > 0 Then
           Dim Parent = Firefox(0).Parent
           Dim RootElement As AutomationElement = AutomationElement.FromHandle(Parent.MainWindowHandle)
           Dim Controls As Condition = New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document)
           Console.WriteLine(RootElement.FindFirst(TreeScope.Descendants, Controls))
           Dim DocElement As AutomationElement = RootElement.FindFirst(TreeScope.Descendants, Controls)
           For Each pattern As AutomationPattern In DocElement.GetSupportedPatterns()
               Console.WriteLine(DocElement.GetSupportedPatterns(0).GetType.FullName)
               If TypeOf DocElement.GetCurrentPattern(pattern) Is ValuePattern Then
                   Console.WriteLine((TryCast(DocElement.GetCurrentPattern(pattern), ValuePattern)).Current.Value.ToString())
               End If
           Next
           'second
           Dim ControlTypeCondition As Condition = New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom)
           Dim CustomControl_Level_1 As AutomationElement = GetAllNextLevelCustomControl(RootElement, ControlTypeCondition)
           'DumpProperty(CustomControl_Level_1, "Level_1")
           For Each CustomControl_Level_2 As AutomationElement In CustomControl_Level_1.FindAll(TreeScope.Children, ControlTypeCondition)
               'DumpProperty(CustomControl_Level_2, "Level_2")
               For Each CustomControl_Level_3 As AutomationElement In CustomControl_Level_2.FindAll(TreeScope.Children, ControlTypeCondition)
                   'DumpProperty(CustomControl_Level_3, "Level_3")
                   GetDocumentFromControl(CustomControl_Level_3)
               Next
           Next
           'freeze
           Dim DocElements As AutomationElementCollection = RootElement.FindAll(TreeScope.Descendants, Controls)
           For Each One As AutomationElement In DocElements
               For Each pattern As AutomationPattern In One.GetSupportedPatterns()
                   If TypeOf One.GetCurrentPattern(pattern) Is ValuePattern Then Console.WriteLine((TryCast(One.GetCurrentPattern(pattern), ValuePattern)).Current.Value.ToString() + Environment.NewLine)
               Next
           Next
           Console.ReadLine()
       End If
   End Sub
   Private Function GetDocumentFromControl(CustomControl As AutomationElement)
       Dim condDocument As Condition = New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document)
       Dim Document1 As AutomationElement = CustomControl.FindFirst(TreeScope.Children, condDocument)
       If Document1 IsNot Nothing Then
           For Each pattern As AutomationPattern In Document1.GetSupportedPatterns()
               If TypeOf Document1.GetCurrentPattern(pattern) Is ValuePattern Then Console.WriteLine((TryCast(Document1.GetCurrentPattern(pattern), ValuePattern)).Current.Value.ToString() + Environment.NewLine)
           Next
       End If
   End Function
   Private Function GetAllNextLevelCustomControl(ByVal rootElement As AutomationElement, ByVal condCustomControl As Condition) As AutomationElement
       Return rootElement.FindAll(TreeScope.Children, condCustomControl).Cast(Of AutomationElement)().ToList().Where(Function(x) x.Current.BoundingRectangle <> System.Windows.Rect.Empty).FirstOrDefault()
   End Function
   Sub DumpProperty(Control As AutomationElement, Title As String)
       Dim D As New ObjectDumper
       Console.WriteLine("===========" & Title & "===========")
       D.Dump(Control, 5)
   End Sub

End Module

''jscher2000 [[#answer-1265625|said]]'' <blockquote> I don't think Firefox exposes tab URLs externally. </blockquote> Thank you, jscher2000, for your answer, but FireFox certainly exposed opened table externally in many-many ways. There is a my simplest test and a result on the screen. But hierarchy of control not always equal, sometimes FF Tabs is placed deeper in hierarhy of automation control. And I don't see a google sometimes. Module Module1 Sub Main() Dim Firefox As Process() = Process.GetProcessesByName("firefox") If Firefox.Length > 0 Then Dim Parent = Firefox(0).Parent Dim RootElement As AutomationElement = AutomationElement.FromHandle(Parent.MainWindowHandle) Dim Controls As Condition = New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document) Console.WriteLine(RootElement.FindFirst(TreeScope.Descendants, Controls)) Dim DocElement As AutomationElement = RootElement.FindFirst(TreeScope.Descendants, Controls) For Each pattern As AutomationPattern In DocElement.GetSupportedPatterns() Console.WriteLine(DocElement.GetSupportedPatterns(0).GetType.FullName) If TypeOf DocElement.GetCurrentPattern(pattern) Is ValuePattern Then Console.WriteLine((TryCast(DocElement.GetCurrentPattern(pattern), ValuePattern)).Current.Value.ToString()) End If Next 'second Dim ControlTypeCondition As Condition = New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom) Dim CustomControl_Level_1 As AutomationElement = GetAllNextLevelCustomControl(RootElement, ControlTypeCondition) 'DumpProperty(CustomControl_Level_1, "Level_1") For Each CustomControl_Level_2 As AutomationElement In CustomControl_Level_1.FindAll(TreeScope.Children, ControlTypeCondition) 'DumpProperty(CustomControl_Level_2, "Level_2") For Each CustomControl_Level_3 As AutomationElement In CustomControl_Level_2.FindAll(TreeScope.Children, ControlTypeCondition) 'DumpProperty(CustomControl_Level_3, "Level_3") GetDocumentFromControl(CustomControl_Level_3) Next Next 'freeze Dim DocElements As AutomationElementCollection = RootElement.FindAll(TreeScope.Descendants, Controls) For Each One As AutomationElement In DocElements For Each pattern As AutomationPattern In One.GetSupportedPatterns() If TypeOf One.GetCurrentPattern(pattern) Is ValuePattern Then Console.WriteLine((TryCast(One.GetCurrentPattern(pattern), ValuePattern)).Current.Value.ToString() + Environment.NewLine) Next Next Console.ReadLine() End If End Sub Private Function GetDocumentFromControl(CustomControl As AutomationElement) Dim condDocument As Condition = New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document) Dim Document1 As AutomationElement = CustomControl.FindFirst(TreeScope.Children, condDocument) If Document1 IsNot Nothing Then For Each pattern As AutomationPattern In Document1.GetSupportedPatterns() If TypeOf Document1.GetCurrentPattern(pattern) Is ValuePattern Then Console.WriteLine((TryCast(Document1.GetCurrentPattern(pattern), ValuePattern)).Current.Value.ToString() + Environment.NewLine) Next End If End Function Private Function GetAllNextLevelCustomControl(ByVal rootElement As AutomationElement, ByVal condCustomControl As Condition) As AutomationElement Return rootElement.FindAll(TreeScope.Children, condCustomControl).Cast(Of AutomationElement)().ToList().Where(Function(x) x.Current.BoundingRectangle <> System.Windows.Rect.Empty).FirstOrDefault() End Function Sub DumpProperty(Control As AutomationElement, Title As String) Dim D As New ObjectDumper Console.WriteLine("===========" & Title & "===========") D.Dump(Control, 5) End Sub End Module

由 kharkov275 於 修改

這篇文章有幫助嗎?
引用
jscher2000
  • Top 10 Contributor
8799 個解決方法 71970 個答案

Hmm, from what I understand of your code, it uses a method available to Windows programs to extract the value of a control used in another program. And the problem you mentioned is that this approach does not return a complete list. I am not aware of any documentation related to using Windows automation with Firefox, but there probably are relevant references on other sites. Or maybe you'll end up writing the definitive documentation.

Hmm, from what I understand of your code, it uses a method available to Windows programs to extract the value of a control used in another program. And the problem you mentioned is that this approach does not return a complete list. I am not aware of any documentation related to using Windows automation with Firefox, but there probably are relevant references on other sites. Or maybe you'll end up writing the definitive documentation.
這篇文章有幫助嗎?
引用

提出問題者

Mr. jscher2000, this is code from my site http://www.vb-net.com/ReadFirefoxUrls/index.htm - any programmer can be use it and expand it to any direction his need. And, at common, I know many different ways to access from any windows program to Firefox, code above is only one way. This way declared by Microsoft as universal access from one program to another. Alternate way is by low level Windows API, for example I write bot to bid in the poker. This screen we can see below. This way is possible to Firefox too, because FF used particular windows API. And there many another way to access FF, for example controlling network communication. I was think you know more about access to FF bypassing simple universal windows ways, but sorry. However, many thank to you, Tab Session Manager is good choice to solve my current problem with save session at night and restore point of working in morning or in a few day and continue working from saved point. Initially, I was want to write my own program to save-restore state of FF to my own program, but right now I will be use existing program - Tab Session Manager Many thank to you, bye

Mr. jscher2000, this is code from my site http://www.vb-net.com/ReadFirefoxUrls/index.htm - any programmer can be use it and expand it to any direction his need. And, at common, I know many different ways to access from any windows program to Firefox, code above is only one way. This way declared by Microsoft as universal access from one program to another. Alternate way is by low level Windows API, for example I write bot to bid in the poker. This screen we can see below. This way is possible to Firefox too, because FF used particular windows API. And there many another way to access FF, for example controlling network communication. I was think you know more about access to FF bypassing simple universal windows ways, but sorry. However, many thank to you, Tab Session Manager is good choice to solve my current problem with save session at night and restore point of working in morning or in a few day and continue working from saved point. Initially, I was want to write my own program to save-restore state of FF to my own program, but right now I will be use existing program - Tab Session Manager Many thank to you, bye
這篇文章有幫助嗎?
引用
問個問題

如果您還沒有帳號,您必須先 登入您的帳號 來回覆文章。請 開始一個新問題