Sign in to follow this  
Followers 0
4Eyes

Trying to read URL from Chrome (yes, still and again)

9 posts in this topic

Folks,

I've been trying to read the current URL from Chrome for some time and tried a few different approaches but with little success, however, I see that Au3Info.exe (the window info tool) does this. I.E. with Chrome open and displaying say www.google.com, start Au3Info, choose the 'Visible Text' tab in Au3Info and you see the title of the tab and on the 2nd line, the url.

My latest attempt is this:

$Title = WinGetTitle("[CLASS:Chrome_WidgetWin_0]", "")
ConsoleWrite("Tab title = '" & $Title & "'" & @CRLF)
ConsoleWrite("Text = " & ControlGetText($Title, "", "[CLASS:Chrome_AutocompleteEditView]") & @CRLF)
ConsoleWrite("Text = " & ControlGetText($Title, "", "[CLASS:Chrome_WidgetWin_0]") & @CRLF)

but it doesn't work. It occasionally shows an incorrect title, but never any text.

Before anybody asks, I want this specifically for Chrome, not Firefox or IE.

Any help would be appreciated as I'd love to put this to bed once and for all. I have such a love/hate relationship with Chrome. Grrr! It's an odd beast to be sure.

4Eyes

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This should get you started.

AutoItSetOption("WinTitleMatchMode", 2)
If @error Then Exit
$1 = WinWaitActive(ControlGetText("[CLASS:Chrome_WidgetWin_0]", " ", WinGetTitle("[CLASS:Chrome_WidgetWin_0]")))

If @error Then
    MsgBox(0,"","FAIL!!!!")
Else
    MsgBox(0, "", ControlgetText($1, "", "Chrome_AutocompleteEditView1" ))
    EndIf

The code gives you the tab URL when you activate chrome.

Edited by xJSLRx

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Try this...Chrome has one blank window and if you select the tab that is not focused, you cannot get the text from the address bar. Test by switching the active tab and run the script

$List = WinList("[REGEXPCLASS:Chrome_WidgetWin_0]")
If Not IsArray($List) Then Exit ;Exit if Chrome is not open

For $i = 1 To $List[0][0]
    If Not WinGetTitle($List[$i][1]) Then ContinueLoop  ;skip balnk Chrome Window
    If Not ControlGetText($List[$i][1], "", "[CLASS:Chrome_AutocompleteEditView]") Then ContinueLoop    ;if Active Tab is not seleceted, Text will be blank so skip
    $Title = WinGetTitle($List[$i][1])
    $TabTitle = ControlGetText($Title, "", "[CLASS:Chrome_WidgetWin_0]")
    $TabURL = ControlGetText($Title, "", "[CLASS:Chrome_AutocompleteEditView]")
    ExitLoop
Next

ConsoleWrite("Window Title = " & $Title & @CRLF)
ConsoleWrite("Tab Title = " & $TabTitle & @CRLF)
ConsoleWrite("Tab URL = " & $TabURL & @CRLF)
Edited by Varian

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Here is a much better example. This is a fluid display

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Result Window", 600, 184, -1, -1, -1, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
$Edit = GUICtrlCreateEdit("", 0, 0, 600, 201, $ES_WANTRETURN)
GUICtrlSetFont(-1, 13)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
    If GUICtrlRead($Edit) <> _GetChromeText() Then GUICtrlSetData($Edit, _GetChromeText())
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _GetChromeText()
    Local $Title, $TabTitle, $TabURL
    Local $List = WinList("[REGEXPCLASS:Chrome_WidgetWin_0]")
    If Not IsArray($List) Then Exit
    For $i = 1 To $List[0][0]
        If Not WinGetTitle($List[$i][1]) Then ContinueLoop
        If Not ControlGetText($List[$i][1], "", "[CLASS:Chrome_AutocompleteEditView]") Then ContinueLoop
        $Title = WinGetTitle($List[$i][1])
        $TabTitle = ControlGetText($Title, "", "[CLASS:Chrome_WidgetWin_0]")
        $TabURL = ControlGetText($Title, "", "[CLASS:Chrome_AutocompleteEditView]")
        ExitLoop
    Next
    Return "Window Title = " & $Title & @CRLF & @CRLF & "Tab Title = " & $TabTitle & @CRLF & @CRLF & "Tab URL = " & $TabURL
EndFunc   ;==>_GetChromeText

EDIT:I forgot to declare variables in the function..the script would break on a blank tab or the "New Tab" page. Fixed that now.

Edited by Varian

Share this post


Link to post
Share on other sites

xJSLRx,

Thanks for your reply although it didn't help.

Varian,

That hits the spot. Thank you. I tried getting window titles with WinList() and comparing PIDs obtained via ProcessList() but it was a nightmare and didn't work well at all. It looks like I was poking around the edges but just couldn't make it happen. Thanks for your efforts, much appreciated. Now, if I could just win 1 game of MineSweeper in expert mode I could die a happy man.

Regards,

4Eyes

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

xJSLRx,

Thanks for your reply although it didn't help.

Varian,

That hits the spot. Thank you. I tried getting window titles with WinList() and comparing PIDs obtained via ProcessList() but it was a nightmare and didn't work well at all. It looks like I was poking around the edges but just couldn't make it happen. Thanks for your efforts, much appreciated. Now, if I could just win 1 game of MineSweeper in expert mode I could die a happy man.

Regards,

4Eyes

No problem, It helped me!

This is an interesting subject and the code I wrote will be pretty useful, especially the navigation part.

AutoItSetOption("WinTitleMatchMode", 2)
If @error Then Exit
While 1
$0 = ControlGetText("[CLASS:Chrome_WidgetWin_0]", " ", WinGetTitle("[CLASS:Chrome_WidgetWin_0]"))
If $0 = "" Then
    ContinueLoop
Else
    $T = ControlgetText($0, "", "Chrome_AutocompleteEditView1")
    IniWrite(@ScriptDir & "\URL.ini","Chrome","URL",$T)
    _1()
EndIf
WEnd

Func _1();This is supposed to check if the url from the ini file differs to the current url
        While 1
        $x = ControlgetText($0, "", "Chrome_AutocompleteEditView1")
        $TT = IniRead(@ScriptDir & "\URL.ini","Chrome","URL",$T)
            MsgBox(0, "", $T)
        If $x = $TT Then
        ContinueLoop
    Else
        ExitLoop
        EndIf
    WEnd
EndFunc

What Im aiming for is recording every url I visit but It still has some bugs, the code above doesn't work but should tell you exactly what I am doing. I'll update it when I finish cause i'm sure some one's gonna get here later via Google and having a larger variety per post is good isn't it?

Edit: No, stick with varian's code or you can edit mine to actually work if my first post's code does not suit you need's. I'm currently encrypting a script and am too into it. I'll look into Chrome's url logging later :)

Edited by xJSLRx

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

xJSLRx,

Certainly, variety is the spice of life and there always seems to be more than one way to skin a cat.

If you need to get url's from IE etc as well then there's been some good examples posted here recently.

4Eyes

Share this post


Link to post
Share on other sites

Sorry to necro this thread but this method, using [CLASS:Chrome_AutocompleteEditView], doesn't seem to work anymore. I don't want to resort to control sending an F6 or !d to highlight the URL bar and clipget to read it - that seems like it would be prone to failure in certain instances.

Is there any other way to do it besides the ghetto way I've mapped out above?

Thanks guys (and sorry again for the necro but this is the most promising thread I've found).

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0