Issue metadata
Sign in to add a comment
|
URL Tracking in VB.net or C#
Reported by
thomasdu...@gmail.com,
Aug 31 2016
|
||||||||||||||||||||||||
Issue description
Chrome Version : 52.0.2743.116 m
URLs (if applicable) :
Other browsers tested:
Add OK or FAIL, along with the version, after other browsers where you
have tested this issue:
Safari:
Firefox:
IE: ok
What steps will reproduce the problem?
(1)
(2)
(3)
What is the expected result?
From one of my computers i can get the URL from the active tab using vb.net code:
Dim procsChrome As Process() = Process.GetProcessesByName("chrome")
For Each chrome1 As Process In procsChrome
If chrome1.MainWindowHandle = IntPtr.Zero Then Continue For
Dim elm As AutomationElement = AutomationElement.FromHandle(chrome1.MainWindowHandle)
Dim elmUrlBar As AutomationElement = elm.FindFirst(TreeScope.Descendants, New PropertyCondition(AutomationElement.NameProperty, "Address and search bar"))
If elmUrlBar IsNot Nothing Then
Dim patterns As AutomationPattern() = elmUrlBar.GetSupportedPatterns()
If patterns.Length > 0 Then
Dim val As ValuePattern = DirectCast(elmUrlBar.GetCurrentPattern(patterns(0)), ValuePattern)
If Not elmUrlBar.GetCurrentPropertyValue(AutomationElement.HasKeyboardFocusProperty) Then
If (URLExists(val.Current.Value)) = False Then
DataGridURL.Rows.Add(Environment.MachineName, Date.Now, val.Current.Value, "Google Chrome")
End If
End If
End If
End If
Next
What happens instead?
On some computers it doesn't work.
Please provide any additional information below. Attach a screenshot if
possible.
Can you implement something in chrome so developers of VB.net and C# can extract the active url's from one of all tabs. Because i'm working in a company where we have 500 computers and we want to get all open url's from IE, Chrome,...
,
Aug 31 2016
I suspect it has something to do with the HWND not being created yet. In Chrome, you have to wait until the page loads before you can be sure that an HWND is present. @dmazzoni, can you provide more guidance?
,
Aug 31 2016
The code i posted in this thread works on 5 or 6 machines to get the url from an active tab. On the other 494 machines i get an empty string as url All these machines work on windows 7 64 bit All of them are having the latest chrome 64bit version. Op 31-aug.-2016 18:02 schreef "elawre… via monorail" < monorail+v2.271331812@chromium.org>:
,
Sep 1 2016
I also get the same effect with another method.
-------------------------------------
----Module---------------------------
-------------------------------------
Imports System.Windows.Automation
Module GoogleChrome
Private Const ChromeProcess As [String] = "chrome"
Private Const AddressCtl As [String] = "Address and search bar"
Public Function GetChromeActiveWindowUrl() As [String]
Dim procs = Process.GetProcessesByName(ChromeProcess)
If (procs.Length = 0) Then
Return [String].Empty
End If
Return procs _
.Where(Function(p) p.MainWindowHandle <> IntPtr.Zero) _
.Select(Function(s) GetUrlControl(s)) _
.Where(Function(p) p IsNot Nothing) _
.Select(Function(s) GetValuePattern(s)) _
.Where(Function(p) p.Item2.Length > 0) _
.Select(Function(s) GetValuePatternUrl(s)) _
.FirstOrDefault
End Function
Private Function GetUrlControl(
proses As Process) _
As AutomationElement
Dim propCondition =
New PropertyCondition(
AutomationElement.NameProperty,
AddressCtl)
Return AutomationElement _
.FromHandle(proses.MainWindowHandle) _
.FindFirst(
TreeScope.Descendants,
propCondition)
End Function
Private Function GetValuePatternUrl(
element As Tuple(Of
AutomationElement, AutomationPattern())) As [String]
Dim ap = element.Item2(0)
Dim ovp = element.Item1.GetCurrentPattern(ap)
Dim vp = CType(ovp, ValuePattern)
Return vp.Current.Value
End Function
Private Function GetValuePattern(
element As AutomationElement) _
As Tuple(Of
AutomationElement,
AutomationPattern())
Return New Tuple(Of
AutomationElement,
AutomationPattern())(
element,
element.GetSupportedPatterns())
End Function
End Module
--------------------
----Usage-----------
--------------------
DataGridURL.Rows.Add(Environment.MachineName, Date.Now, GetChromeActiveWindowUrl(), "Google Chrome")
,
Sep 8 2016
Thank you for providing more feedback. Adding requester "elawrence@chromium.org" for another review and adding "Needs-Review" label for tracking. For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
,
Sep 8 2016
When you step through your code in the debugger, at which line is it failing to behave as expected? Are any exceptions thrown?
,
Sep 8 2016
For what it's worth, this code works (mostly) fine on the PC I tested it on. Are the PCs in question running 32bit or 64bit Windows? Is your app 32bit or 64bit? Is Chrome 32bit or 64bit? One fundamental problem with your code is that it looks at the Chrome processes and asks each one what its main window handle is, then uses UI automation to interrogate that Window for the text of the address bar. This is problematic because all windows spawned from a single Chrome instance all end up having the same MainWindowHandle, and as such you end up getting only one URL per instance of Chrome, no matter how many windows you have open. (And no matter how many tabs each window has). To get the currently active URL in all open Windows, you need to approach this a different way. You need to call user32.dll's EnumWindows function to enumerate ALL windows on the system and for each determine if it's owned by Chrome and if so, then use UIAutomation to determine the URL (see e.g. http://stackoverflow.com/a/30628132/126229). This will give you the active URL for each top-level Chrome window (but will not give you the URLs of the tabs).
,
Sep 8 2016
,
Sep 11 2016
Everything is 64 bit and i don't get exeptions.. Op 8-sep.-2016 18:40 schreef "elawre… via monorail" < monorail+v2.271331812@chromium.org>:
,
Sep 18 2016
Thank you for providing more feedback. Adding requester "elawrence@chromium.org" for another review and adding "Needs-Review" label for tracking. For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
,
Sep 18 2016
Without a repro environment, I don't think this is actionable. Due to the limitations I describe in #7 it may make the most sense to treat this as a feature request for a mechanism to collect tab URLs from outside the process via something other than the very limited accessibility API.
,
Sep 18 2016
Okay. Then you may thread this as a feature request. It would be a benefit for many companies. Op 18-sep.-2016 21:05 schreef "elawre… via monorail" < monorail+v2.271331812@chromium.org>:
,
Mar 13 2017
Cleaning up "Needs-Review" label as we are not using this label for triage anymore. Ref bug for this cleanup 684919
,
Mar 27 2017
,
Apr 21 2017
,
Apr 21 2017
,
Oct 9 2017
Hello, We've had many updates for Chrome/ChromeOS since this bug was last updated. For now, I am resolving this bug as Archived. Please try again on the latest version and reopen this issue if this feature request is still desired. Thanks, Laura
,
May 22 2018
This symptom of not able to get the URL from chrome is happening when i run chrome as an administrator. |
|||||||||||||||||||||||||
►
Sign in to add a comment |
|||||||||||||||||||||||||
Comment 1 by elawrence@chromium.org
, Aug 31 2016Labels: Needs-Feedback