Although It Comes with a Bit of a Learning Curve, the Chrome.ahk AutoHotkey Library Offers More Precise Source-Level Web Page Automation
This time, I introduce source-level Web page automation running a short test script after installing a set of Google Chrome AutoHotkey source-level Web page automation tools—Geekdude’s Chrome.ahk Library. I’ve set up a test page called “Jack’s AutoHotkey Chrome Test Page” for a quick trial of the tools. (When initially viewing the test Web page, you should see a set of three empty input fields: First Name, Last Name, and Street Address.) In this blog, I discuss how to install and set up the Chrome.ahk tools—then access the setup by running a sample AutoHotkey script that automatically fills in the three input fields:
If you can get this test script running with your Chrome browser, then a totally new world of Web page automation opens up.
Creating the Source-Level Connection
Note: While, personally, I did not find it easy to get the Chrome.ahk Library up and running, it’s quite possible that you may find success with the test script on your first try. I include a troubleshooting section in this blog for those who (like me) always seem to run into trouble. The following discussion includes the steps necessary for success.
Before running the test script, take the following actions:
- Download the Chrome.ahk Library
- Add the Chrome debugger switch to the target of the System Tray shortcut in order to connect to Chrome through the DevTools Protocol on LocalHost
#Includethe correct Chrome.ahk path in the test script.
1. Download the Chrome.ahk Library
The first step requires you to download the Chrome.ahk ZIP file and extract its contents. Be sure you download the ZIP file which contains all the required pieces (Chrome.ahk_v1.2.zip).
Extract (unzip) the files to the location where you normally run your AutoHotkey scripts. I use
C:\AutoHotkey as my primary script folder, but your folder may differ. Make sure you change the
#Include path for the Chrome.ahk file in the test script to match your expanded ZIP file location.
Note: Although the ZIP file includes example scripts, when I attempted to run them, they seemed pretty enigmatic. That’s why I set up a simple bare-bones test Web page for testing the tools. Also, the video by GeekDude and Joe Glines available at the AutoHotkey forum (through no fault of their own) came across at a level slightly over my head. I had to watch the video a couple of times for the techniques to sink in. Eventually, the light turned on.
2. Add Debugging Port to Chrome Shortcut
To connect to the Chrome backdoor, you must append code to the Target of the Chrome shortcut in the System Tray.
- Right-click on the Chrome icon in the System Tray.
- Right-click on “Google Chrome” in the main menu.
- Select “Properties” from the menu.
The “Google Chrome Properties” window opens.
Select the Shortcut tab and append (with a leading space) the following (in red) to the Target file path:
When appended to the primary Google Chrome target file (EXE) path, this argument opens debugging tool access to Chrome.
Before running the test script, close all other Chrome windows—at least initially. An open Chrome window without the debugger access can interfere with Chrome.ahk operations on a Web page.
Note: I ran into a number of issues causing me temporary setbacks:
- In the beginning, I was frustrated by the
http.send()error (discussed below). Eventually, I found a solution through one of the comments in the AutoHotkey forum. If you already use remote access (or other localhost applications) with your computer, you may not encounter this error.
- The first time I run the test script after rebooting, it tends to fail. However, on the second run, it starts working again(?). Try again.
- Sometimes, after a period of time, the test script just stopped functioning. Rebooting usually restored function.
Run the Test Script
The following test script may run perfectly after installing the Chrome.zip files and modifying your Google Chrome shortcut target:
Update November 5, 2020: My frustration with the
http.send() error continued in a random fashion—although worse at various times. I tracked it down to the
ChromeInst := new Chrome("ChromeProfile") line of code and added a
Sleep, 1000 command (line 7) to allow time for the the script to complete the connection. The script works more reliably now, although you may need a longer (or shorter) time period for your system. I speculate the reliability of this fix depends upon the speed of the computer processor and the demands on it. This does not override the original
http.send() error discussed below.
If (after ensuring you inserted the correct path into the
#Include statement) running this test script inserts my name and a fake street into the test Web page, then you don’t need to proceed any further in this blog. It’s working!
Tip: Whenever writing new scripts, ensure the code contains the required ProfilePath—Chrome user profile—relative to the working directory:
ChromeInst := new Chrome("ChromeProfile")
For the Chrome.ahk tools to run properly, this snippet must appear in any new script.
If the test script fails (i.e. nothing happens or the page opens with blank fields), continue reading for troubleshooting tips.
Troubleshooting When the Script Finds No Connection to Chrome
The most common error I received pointed to
http.send() as its source. The hookup between the script and Chrome failed—a broken connection.
This error dogged me right from the beginning. It took a while to find a fix. At times, I thought about giving up but I eventually stumbled across the technique below.
Note: I’m not sure how the various Windows settings discussed in this blog interact. Some people may find the following works while others may need the answer found toward the end of this blog. During testing, I turned a number of settings on and off—ultimately finding that I must activate Windows Internet Information Services (IIS—a local Web server) in some form.
Turning on Windows Internet Information Services (IIS)
Depending upon how you use your computer (e.g. remote connections to your computer), your Windows Internet Information Services (IIS) may or may not be active. IIS can turn your computer into a remote Web server capable of hosting Web pages for remote browsers. (Generally, if turned on, you can access this local Web server using the browser address
127.0.0.1 in your Web browser.) If you have never installed software which requires IIS, then you may need to activate a piece of the service to allow access for the Chrome.ahk tools. I did!
While my setup didn’t require activation of the entire set of IIS, at a minimum, I had to turn on Web Management Tools.
I followed these steps:
- Open the Control Panel Programs and Features window.
- Click “Turn Windows features on or off” on the left side of the window.
- Activate “Web Management Tools” in the “Internet Information Services” section.
1. Programs and Features/ Windows Features
Open the Control Panel and access Programs and Features.
2. Turn Windows Features On and Off
Click “Turn Windows features on or off” on the left side of the window to open the Windows Features window.
Check the boxes Internet Information Services and Web Management Tools, then OK. The Windows operating system then locates the required system files and implements the changes. (Be patient. Windows can take a while to complete this process.)
After activating the new setup, the test script should start working. If not, try rebooting—although sources say you should not need to restart your system.
Note: You don’t need to implement all of the World Wide Web Services but, if you would like to see what they do, check the World Wide Web Services box in the Windows Features window before clicking OK. Then, open “localhost” or “127.0.0.1” in your Web browser view the local Web hosting system:
Still not working? Try the following.
I tested this recommendation but it had no effect on my situation—either when turned on or off. However, it seemed to work for other people. Go figure. Since I don’t really know how all these features (and possible security settings) actually interact, I take the position that you should keep trying things until something works.
Hopefully, you now have the test script running—inserting my name into the test page. If you run into other problems and none of my tips help, yet you manage to get the Chrome.ahk tools working, please leave a comment about your experience.
Click the Follow button at the top of the sidebar on the right of this page for e-mail notification of new blogs. (If you’re reading this on a tablet or your phone, then you must scroll all the way to the end of the blog—pass any comments—to find the Follow button.)
This post was proofread by Grammarly
(Any other mistakes are all mine.)
(Full disclosure: If you sign up for a free Grammarly account, I get 20¢. I use the spelling/grammar checking service all the time, but, then again, I write a lot more than most people. I recommend Grammarly because it works and it’s free.)
Find my AutoHotkey books at ComputorEdge E-Books!
Find quick-start AutoHotkey classes at “Robotic Desktop Automation with AutoHotkey“!
14 thoughts on “Installing Chrome.ahk AutoHotkey Web Page Automation Tools”
This series looks very interesting and I will try it out. A couple of questions:
– I’m not a Chrome user. Does this work on Microsoft’s version of Chromium (Edge)?
– Firefox is my primary browser. Anything like this for it?
It should work with Chromium-based browsers but I think that you need to modify the code in Chrome.ahk.
Firefox is not Chromium-based. Not sure if anyone has similar AutoHotkey tools for Firefox.
[…] screen, Chrome.ahk interacts directly with the inner workings of the loaded Web page. (See “Installing Chrome.ahk AutoHotkey Web Page Automation Tools” to get the library loaded.) To call the Chrome.ahk functions, we need to identify the […]
[…] Installing Chrome.ahk AutoHotkey Web Page Automation Tools […]
This looks very interesting as I recently used AutoHotKey to automate adding videos to a YouTube playlist I made, and have been wondering what else I could do with it.
I haven’t tried anything from here yet, but I just wanted to ask a question. Wouldn’t a way to avoid getting the file path wrong in the #Include line be to add the Chrome.ahk file to a local library? You mentioned your AutoHotKey folder’s location is C:\AutoHotKey, so if you saved the Chrome.ahk file at the location C:\AutoHotKey\Lib you wouldn’t need the #Include line at all; so no worries about getting the file path wrong!
I used it for my automation script mentioned above and it worked fine there, so I imagine it would work just as well here, but maybe there’s a reason why it’s better to use the #Include command that I’m not aware of.
Many thanks for the cool blog and best wishes for 2021!
hi my name is Alexis A.D …hablo español :V … segun mi experiencia habia tenido un error propio en el archivo chrome.ahk … como en la linea 76 masomenos puede encontrase -> …\App Pahs\.. ; ahí lo corregi por App Paths
Hi Alexis, I just noticed the same thing. I’ll go to Git to see a change can be merged. Thanks.
Thanks for this great article. I got Chrome.ahk working for some time now. To get it working I had to deploy the following solutions:
1) Sleep,3000 after creating the chromeinstance.
2) Update the internet explorer setting from your last suggestion.
I did not touched the Internet Information Services and Web Management Tools, but I will check this.
Still from time to time I lose connections (message: “Not connected to Tab”)
Here is what I do then to overcome this:
1) Check if there are no open Chrome windows. If there are close them.
2) Delete the Chromeprofile: FileRemoveDir, ChromeProfile,1 and create a new one.
Most of the time open chrome windows are the issue.
Thanks very much for this page !
That would be nice to start this article and explain that we need to download and install autohokey tool from https://www.autohotkey.com/ . Then we can execute a .ahk file. It was not clear for me and didn’t understand “run”.
Trying your script under windows 10, I could’nt create ChromeProfile and add the http.send() error.
In the script, just change and add ChromeProfile path, and it works, without installing IIS :
; Required to initiate profile
; FileCreateDir, ChromeProfile
ChromeProfile := “C:\Users\” . A_UserName . “\AppData\Local\Google\Chrome\User Data\Default”
ChromeInst := new Chrome(ChromeProfile)
LikeLiked by 1 person
It was great, thank you
after go to Programs and Features you should to restart
Hi. I’m trying to replicate your results, but when I run the script I get a “SecurityError” popup window and then nothing works. Any ideas what I’m doing wrong?
I have been using chrome.ahk with Chrome for quite some time with great success. But the last two days whenever I attempt to run it I get a SecurityError. Any suggestions? I am running Chrome in debugging mode as I have checked this.