New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 642765 link

Starred by 2 users

Issue metadata

Status: Archived
Owner: ----
Closed: Oct 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug
Team-Accessibility



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,...

 
Components: UI>Accessibility
Labels: Needs-Feedback
When you say "it doesn't work" can you please be more specific about what you mean?

This is either a "Bug" in accessibility (the API being used) or a "Feature" Request (for some new API exposed to Windows applications).

Comment 2 by nek...@chromium.org, Aug 31 2016

Cc: nek...@chromium.org dmazz...@chromium.org
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?
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>:
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")

Project Member

Comment 5 by sheriffbot@chromium.org, Sep 8 2016

Labels: -Needs-Feedback Needs-Review
Owner: elawrence@chromium.org
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
Labels: -Needs-Review Needs-Feedback
When you step through your code in the debugger, at which line is it failing to behave as expected? Are any exceptions thrown? 
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).
Owner: ----
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>:
Project Member

Comment 10 by sheriffbot@chromium.org, Sep 18 2016

Labels: -Needs-Feedback Needs-Review
Owner: elawrence@chromium.org
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
Owner: ----
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. 
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>:
Labels: -Needs-Review
Cleaning up "Needs-Review" label as we are not using this label for triage anymore. Ref bug for this cleanup 684919
Labels: NewComponent-Accessibility NewComponent-Accessibility-Compatibility
Components: UI>Accessibility>Compatibility
Components: -UI>Accessibility
Labels: -newcomponent-accessibility-compatibility -newcomponent-accessibility
Status: Archived (was: Unconfirmed)
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

Comment 18 by yezdi...@gmail.com, 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