X
Tap here to go to the mobile version of the site.

Support Forum

Read all opened URLs in all tabs

Posted

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.

Chosen solution

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:

Read this answer in context 1
Quote
jscher2000
  • Top 10 Contributor
8799 solutions 71970 answers

Chosen Solution

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/
Was this helpful to you? 1
Quote
cor-el
  • Top 10 Contributor
  • Moderator
17588 solutions 159105 answers

Helpful Reply

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
Was this helpful to you? 1
Quote

Question owner

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

Modified by kharkov275

Was this helpful to you?
Quote
jscher2000
  • Top 10 Contributor
8799 solutions 71970 answers

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.
Was this helpful to you?
Quote

Question owner

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
Was this helpful to you?
Quote
Ask a question

You must log in to your account to reply to posts. Please start a new question, if you do not have an account yet.