Get the URL from Google Chrome addressbar

795 views
Skip to first unread message

Rommel Escuadro

unread,
Sep 14, 2015, 1:54:11 PM9/14/15
to Google Chrome Developer Tools
For simplicity of this app that I am making, I am still using VB6.

I have researched some on Google on how to get the URL from the Google Chrome browser but unfortunately it only gives the page title.  Below is the code that I got.

Option Explicit

Private Const WM_GETTEXT = &HD
Private Const WM_GETTEXTLENGTH = &HE
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

Private Sub Command1_Click()
    Dim dhWnd As Long
    Dim chWnd As Long
    
    Dim Web_Caption As String * 2560
    Dim Web_hWnd As Long
    
    Dim URL As String * 2560
    Dim URL_hWnd As Long
    
    dhWnd = GetDesktopWindow
    chWnd = FindWindowEx(0, 0, "Chrome_WidgetWin_1", vbNullString)
    Web_hWnd = FindWindowEx(dhWnd, chWnd, "Chrome_WidgetWin_1", vbNullString)
    URL_hWnd = FindWindowEx(Web_hWnd, 0, "Chrome_OmniboxView", vbNullString)
    
    Call SendMessage(Web_hWnd, WM_GETTEXT, 2560, ByVal Web_Caption)
    Call SendMessage(URL_hWnd, WM_GETTEXT, 2560, ByVal URL)
    
    Text1.Text = Split(Web_Caption, Chr(0))(0) & vbCrLf & Split(URL, Chr(0))(0)
    
End Sub

I have already asked from different forums on how to do this but they have no answer and so I would like to try to ask help here.
I hope somebody can help me get the URL of Google Chrome.


PhistucK

unread,
Sep 14, 2015, 2:01:00 PM9/14/15
to Google Chrome Developer Tools
This is not the right group also, sorry.
There is no right group, because what you are doing may break at any time.

You can create an extension that uses native messaging to talk to your native application and pass the URL of the current tab to it.
This is the only supported and stable way.


PhistucK

--
You received this message because you are subscribed to the Google Groups "Google Chrome Developer Tools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-chrome-develo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-chrome-developer-tools/5a78cc25-b9b4-4cd1-b8a9-166e5c8cca88%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages