After developing my first Chrome extension to retrieve all URLs from Google chrome, I have been trying to reproduce the same behaviour using Delphi, but it was impossible. Chrome is still adding some new features and extending their extensions for developers. For example, others navigators such as Internet Explorer and Firefox they have a DDE extension to retrieve some of the properties but not available for Chrome.
The best way I found was using FindWindow and SendMessage windows functions to get the text from the tab and get tue URL. It's not a win solution but will help you to retrieve the URL of the active page without copy-paste action, just by switching to the next tab and retrieving data from the tool.
The basic code to achieve this is the following one:
function GetChromeActiveTabURL(Wnd: HWnd; Param: LParam): Bool; stdcall;
var
urls: TStrings;
hWndMainWindow, hWndTab: HWND;
Buffer : array[0..255] of Char;
res : boolean;
begin
res := true;
urls := TStrings(Param);
SendMessage(Wnd, WM_GETTEXT, Length(Buffer), integer(@Buffer[0]));
hWndMainWindow := FindWindow('Chrome_WidgetWin_0', Buffer);
application.ProcessMessages;
if hWndMainWindow <> 0 then
begin
hWndTab := FindWindowEx(hWndMainWindow, 0, 'Chrome_AutocompleteEditView', nil);
if hWndTab <> 0 then
begin
SendMessage(hWndTab, WM_GETTEXT, Length(Buffer), integer(@Buffer));
urls.Add(Buffer);
res := false;
end;
end;
Result := res;
end;
procedure TUrlChrome.GetUrl(Sender: TObject);
var
Urls: TStringList;
begin
Urls := TStringList.Create;
try
EnumWindows(@GetChromeActiveTabURL, LParam(Urls));
Memo1.Lines.AddStrings(Urls);
finally
FreeAndNil(Urls);
end;
end;
To get the class name window, we can use Winspector to inspect chrome and get the names for the main window and for the tabs:
Chrome_WidgetWin_0:
Chrome_AutocompleteEditView:
And you can get the tool from here: ThundaxChromeURL.
Chrome_WidgetWin_0:
Chrome_AutocompleteEditView:
And you can get the tool from here: ThundaxChromeURL.
I'm not proud of this solution, but at least it will work for current versions of Chrome. I also recommend to give a go to my chrome extension (It's not been published into Chrome market, it turns out that you have to pay a $5.00 fee), that is much better than the tool as it's able to get all urls.
Related links:
- How to get url from chrome.
- WinsPector Download.
- EnumWindows function.
- Get list opened windows.
- Get url instances internet explorer.
- FindWindowEx function.
- Sending messages to Chrome.
- GetWindow function.
- Enumerate windows and child windows.
- Enum child windows.
- Enum child windows treeview.
- Get handles of tabs.
- EnumChildWindows function.














