Sunday, 18 September 2011

Get Chrome active tab URL using Delphi

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;
  urls: TStrings;
  hWndMainWindow, hWndTab: HWND;
  Buffer : array[0..255] of Char;
  res : boolean;
  res := true;
  urls := TStrings(Param);
  SendMessage(Wnd, WM_GETTEXT, Length(Buffer), integer(@Buffer[0]));
  hWndMainWindow := FindWindow('Chrome_WidgetWin_0', Buffer);
  if hWndMainWindow <> 0 then
    hWndTab := FindWindowEx(hWndMainWindow, 0, 'Chrome_AutocompleteEditView', nil);
    if hWndTab <> 0 then
      SendMessage(hWndTab, WM_GETTEXT, Length(Buffer), integer(@Buffer));
      res := false;
  Result := res;

procedure TUrlChrome.GetUrl(Sender: TObject);
  Urls: TStringList;
  Urls := TStringList.Create;
    EnumWindows(@GetChromeActiveTabURL, LParam(Urls));

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:



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:

Saturday, 17 September 2011

My first Google Chrome extension (Get all URLs from Google Chrome tabs)

As a good internet researcher I always have hundreds of tabs opened in my Chrome navigator and sometimes I find a bit of chore to copy and paste all the URL that I have done a research on and that any other day I would be using again. So, that's my extension about, to display in a pop up window all the url's from all tabs to then copy them without problems (the correct name would be [search purposes] -> Get all URLs from Google Chrome tabs).
I have been struggling to write a little tool using Delphi, but it only works with Internet explorer and Mozilla firefox, so I thought it could be great to give chrome extensions a try. 
It is quite easy to develop and debug using all the development tools available from the navigator itself. As in the following example, I have opened 3 new tabs with the URL, and if we click the extension button, will get a pop up list with the URLs from all tabs:

The source code is as follows:

  "name": "Get All URL's Extension by Jordi Corbilla",
  "version": "1.0",
  "description": "Extension to display all the URL's from all TABs.",
  "browser_action": {
    "default_icon": "icon.ico",
    "popup": "urlList.html"
  "permissions": [
  "icons" : {

    "48" : "icon.ico",

    "128" : "icon.ico"


 * Copyright (c) 2011 Jordi Corbilla. All rights reserved.  
      chrome.tabs.getAllInWindow(null, function(tabs) {

      function myFunction(tablink) {
        var oNewNode = document.createElement("LI");
    <div>URL List</div>
    <ul ID = urlList>

You can download the extension from here: To install, you only need to unzip the file and then go to chrome://extensions/, expand developer mode and load my extension (from the unzipped folder):

As the extension uses the console log method, you can see all the links in the console (just for debug purposes, but it's really good to have a go on it).

Just right click on the extension icon and then "Inspect Pop-up" and you'll see the following window with the current list of urls:

Enjoy the extension!.

Related links: