Notes from Create and connect to new Chrome profiles with AutoHotkey
00:09 There’s been a lot of confusion on Chrome profiles. What they are, why you should concern yourself with them when using AutoHotkey.
00:23 Your Chrome profile is what keeps you logged into websites, connected to Google, etc. Most of the time you won’t need access to your entire Chrome profile. But you might want to start with a blank slate if you’re distributing your code to people. Or you want to create a new instance of Chrome that you don’t want attached to an existing Chrome tab. For any of those, you need to have a Chrome profile
01:17 This is because most people don’t have the remote debugging flag on their default shortcut. If you launch chrome with debugging code, it will automatically group it with the current process window.
02:38 So instead of spawning a new Chrome window that is listening to the debug window, it will open a new page on the existing Chrome instance without the debugging access (even though you specified debugging)
02:52 So in order to get Chrome to open a new instance, you need to use the Chrome profile.
03:51 Create a folder (name it what you want) and tell Chrome to use it the profile flag. “–user data-dir” with your directory i.e. “–user data-dir-C:\temp\newProfile”
05:18 Looking in the profile folder, you can see Chrome has generated a bunch of files. Things like Cookies, browser history, etc. Everything Chrome remembers…
05:47 If you’re targeting portable Chrome, making sure you have this profile set correctly can be a big deal! If you use AutoHotkey to launch portable Chrome, it might still load the default profile. Make sure you specify the Chrome profile!
07:32 Everywhere you would have used Chrome. In your script, use ChromeInst. (i.e. Instead of Chrome.GetPage use ChromeInst.GetPage.
07:32 That tells Chrome to look for this new / specific instance of Chrome instead of the default version. Remember, it’s only “new” right after you make it.
Here we continue with GeekDude working with Chrome and AutoHotkey extracting data from a webpage. This session we focus on getting lists and leverage JSON, Chrome.Jxon_Dump, JSON.stringify, Chrome.Jxon_Load and jQuery.
The great news is that GeekDude explained how we can see the Reddit site the way it was the below video!
AutoHotkey script for Automating Chrome to Set Text & Click a button
#Include ;Remember to put Chrome in your library folder
page:=Chrome.GetPageByTitle("AutoHotkey Community","contains") ;This will connect to the second index of a specific tab
MsgBox % "That wasn' t object / the page wasn't found"
Variable =document.querySelector('#keywords').value ='Chrome.ahk'
page.Evaluate("document.querySelector('#keywords').value ='" var "'")
page.Evaluate("document.querySelector('#search > fieldset > button').value ='Chrome.ahk'")
Notes for Automating Chrome to Set Text & Click a button
00:36 Go to AutoHotkey.com/boards/
00:44 Connect to tab using Chrome.GetPageByTitle(“AutoHotkey Community”) ;the default matchtype is “starts with”
01:23 Look at page structure using right-click and Inspect. This opends Devtools with that element selected.
01:46 It has an ID of “keywords”, copy js path. Which will give you queryselector(“#keywords”)
02:26 Use the .value to set some text in that box.
05:54 The button is right next to the input. You can go back to the page and right-click the button, then hit Inspect
06:13 Test the new js path. Instead of using .value, use .click
06:42 Test in Chrome developer tool
07:18 When running an Evaluate method, it waits for the previous Evaluate to finish (so no need to sleep between them).
07:44 If you run into a problem where you think it is happening too quickly, check the forum for some solutions
08:40 Sometimes what you want to input won’t always be a static string. If you’re trying to reference a variable, you need to use the expression syntax. In an expression, you’re not just assigning text, you’re doing math or making function calls.
page.Evaluate(“document.querySelector(‘#keywords’).value ='” var “‘”) “‘”)
10:48 This works because AutoHotkey splits everything up on a given line. First is a name of a function, then says this is inside the function, then this is text inside a function. Then builds from left to right as to the string that will be used.
12:15 AutoHotkey proceeds left to right when evaluating an expression
12:40 when you use := you’re in expression assignment mode.
13:25 With just single = you’re in plain-text mode. It reads it as text
15:00 When automating a site, you don’t know what kind of buffer’s they have to prevent scraping / botting.
15:49 When you start automating, you might start seeing Captcha’s everywhere
16:04 Sites get really good at looking like a normal site to a user, but looking like an impenetrable fortress to code
9:00 In https://p.ahkscript.org/index.js you can see how that page talks to Ace. It could give you information on how to do it. Mimic what the page itself is doing. Not all sites are as easy as this to see what does
10:00 In this example, It creates an Editor variable and calls all of the editor commands on that.
10:23 Look back to Ace.js documentation you can see Editor is a section of the documentation. This shows all the different methods to communicate with an Ace control.
10:47 Since we want to set text look for one that does that. We’ll use Insert function (Inserts text into wherever the cursor is pointing.) Insert(String text)
11:15 In the pastebin code’s index.js we see everything is called with editor dot (editor.) method name
11:30 Go to Console within the Chrome debugging view (Control+Shift+i)
11:48 Look for the variable Editor by typing Editor. It should respond showing you that it exists and is available
11:56 Auto-Assist works. Try typing Editor.Insert (because insert is a method) . Give it some text to test.
12:17 The text should show up on the pastebin page. 😊
12:28 Take it over to your AutoHotkey code and try it from there using Page.Evaluate
13:00 You could use the legacy assignment to set it. But this gives us 2 lines of code
16:12 Inspect the code for mytextarea.net and you’ll see it is literally just a textbox
16:20 Let’s navigate to that page. You’ll see we have to find a different way to connect as every page is unique.
17:31 When in DevTools console, right click on the element you want, then Copy, and select Copy JS path (Selector is also helpful)
18:00 So use that path, then we want to get it’s value
document.querySelector(“body > textarea”).value
18:48 this uses QuerySelector which returns the first instance. QuerySelectorAll returns an array.
20:14 As long as you copy js Path you’ll probably get something useful (not sure if it is the DOM or how it is decided)
20:20 Any tools you can use like iWB2 learner tool for Chrome- No, GeekDude not aware
21:00 Here we’ve access a value. Let’s set a new value