Page 2 of 34

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Posted: 25 Jan 2018, 17:04
by jeeswg
- Is there a way to get the urls for all open tabs directly? Instead of Ctrl+Tab and using Acc/Ctrl+C.
- Many thanks for this GeekDude.

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Posted: 25 Jan 2018, 23:14
by geek
DanielToward13 wrote:Thanks GeekDude. That’s great!
:)
DanielToward13 wrote:is there a way to get the scroll bar position in order to know where in the page the current view is?
You could run some javascript on the page that gets the scroll position and use the returned value. For example:

Code: Select all

Loop
{
    Position := Tab.Evaluate("window.pageYOffset / (document.body.clientHeight - window.innerHeight)").value
    ToolTip, %Position%
    Sleep, 500
}

jeeswg wrote:- Is there a way to get the urls for all open tabs directly? Instead of Ctrl+Tab and using Acc/Ctrl+C.
Chrome.GetTabs() returns an array of all loaded tabs/pages/documents (including also extension configuration pages).

Code: Select all

for Index, Tab in Chrome.GetTabs()
    MsgBox, % "type: " Tab.type "`nurl: " Tab.url
jeeswg wrote:- Many thanks for this GeekDude.
:)

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Posted: 28 Jan 2018, 22:25
by Cerberus
Extremely interesting! Bookmarked.

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Posted: 29 Jan 2018, 02:26
by arcticir
How do turn off the left|right|other tab?

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Posted: 02 Mar 2018, 23:31
by ibbs
Good stuff, was wondering if anyone has played around with any chromecast automation yet? Haven't had much luck here...

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Posted: 03 Mar 2018, 05:03
by SL5
First fix was easy. Simply add https://github.com/G33kDude/WebSocket.ahk , https://github.com/cocobelgica/AutoHotkey-JSON to the already existing (empty) Folders.

But then i got this error mesage by starting example https://github.com/G33kDude/Chrome.ahk/ ... jectJS.ahk
This error happens inside Jxon_Dump(obj, indent:="", lvl:=1){ ... https://github.com/cocobelgica/AutoHotk ... n.ahk#L174

Code: Select all

------- AHKVersion 1.1.28.00 --------------------
InjectJS.ahk > Jxon.ahk (174) : ==> Call to nonexistent function.
Specifically: Jxon_Dump(k) : q . k . q ) .  ( indent ? ": " : ":" )
>Exit code: 2    Time: 0.5602
i dont know why this recursive call not works. hmm

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Posted: 05 Mar 2018, 13:30
by geek
SL5 wrote:First fix was easy. Simply add https://github.com/G33kDude/WebSocket.ahk , https://github.com/cocobelgica/AutoHotkey-JSON to the already existing (empty) Folders.

But then i got this error mesage by starting example https://github.com/G33kDude/Chrome.ahk/ ... jectJS.ahk
This error happens inside Jxon_Dump(obj, indent:="", lvl:=1){ ... https://github.com/cocobelgica/AutoHotk ... n.ahk#L174

Code: Select all

------- AHKVersion 1.1.28.00 --------------------
InjectJS.ahk > Jxon.ahk (174) : ==> Call to nonexistent function.
Specifically: Jxon_Dump(k) : q . k . q ) .  ( indent ? ": " : ":" )
>Exit code: 2    Time: 0.5602
i dont know why this recursive call not works. hmm
Chrome.ahk depends on this specific version https://github.com/G33kDude/AutoHotkey- ... 38238f81e1 of AutoHotkey-JSON that has been forked and modified from Cocobelgica's original to allow for Boolean JSON values and to allow it to exist alongside other versions of AutoHotkey-JSON. You can find that version by clicking through the repository on the GitHub webpage, or by going to the releases tab and downloading the release which includes all of the required dependencies.
GeekDude wrote:Make sure you're downloading the release file "Chrome.ahk_v1.0.zip" from the releases page, not the source code. As you have learned, GitHub does not include submodules (i.e. AutoHotkey-JSON and WebSocket.ahk) in its source downloads. The release has all the #Include's built in (no lib folder needed :) ).

Image

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Posted: 08 Mar 2018, 19:41
by Shadowpheonix
In the "pastebin.ahk" example that GeekDude was nice enough to include in the release package, the Tab.Call("DOM.setAttributeValue", {"nodeId": NameNode.NodeId, "name": "value", "value": "ChromeBot"}) line assigns a value to an input field. How would I go about retrieving the value after it was assigned?

Looking over the protocol documentation, there does not appear to be a DOM.getAttributeValue or anything similar. The following snippet is the best I could come up with, but all I get is a single message box with "attributes" = ""...

Code: Select all

NameNode := Tab.Call("DOM.querySelector", {"nodeId": RootNode.nodeId, "selector": "input[name=name]"})
Tab.Call("DOM.setAttributeValue", {"nodeId": NameNode.NodeId, "name": "value", "value": "ChromeBot"})

TheNode := Tab.Call("DOM.getAttributes", {"nodeId": NameNode.NodeId})
For k, v in TheNode
	MsgBox "%k%" = "%v%"

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Posted: 08 Mar 2018, 20:16
by Joe Glines
Shadowpheonix wrote:In the "pastebin.ahk" example that GeekDude was nice enough to include in the release package, the Tab.Call("DOM.setAttributeValue", {"nodeId": NameNode.NodeId, "name": "value", "value": "ChromeBot"}) line assigns a value to an input field. How would I go about retrieving the value after it was assigned?
I don't have an example I can post right now but I "solved this" by inserting Java script.

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Posted: 11 Mar 2018, 13:43
by printer
I want to do Page.printToPDF with a few parameters on a local .html file. Can Chrome.ahk help me do that without rendering the .html in the Chrome window? Any code examples for that would be very appreciated. I want to do the conversion with as little delay as possible.

There is also the simpler and headless command line method

Code: Select all

chrome --headless --disable-gpu --print-to-pdf="C:/test/1.pdf" "C:\test\1.html"
But apparently the printToPDF parameters aren't and won't be implemented for the command line command.

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Posted: 13 Mar 2018, 12:24
by Guest
Any particular reason to use Chrome to print pdfs? There are headless solutions which easy scripting options:

* http://phantomjs.org/ (google phantomjs print pdf for example scripts, you don't need to install it, just unzip the download)
* https://github.com/wkhtmltopdf/wkhtmltopdf/

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Posted: 13 Mar 2018, 15:12
by kunkel321
Thanks for your work on this, GeekDude! It's a bit above my ability to fully understand, but I wonder: Would it be possible to use this for setting the default printer in Chrome? I have a nice AHK script that (at system startup) reads my IP address, then sets my default Windows printer. Chrome doesn't use the Windows default printer though. It merely reverts to whatever printer was last used.

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Posted: 14 Mar 2018, 05:51
by printer
Guest wrote:Any particular reason to use Chrome to print pdfs? There are headless solutions which easy scripting options:

* http://phantomjs.org/ (google phantomjs print pdf for example scripts, you don't need to install it, just unzip the download)
* https://github.com/wkhtmltopdf/wkhtmltopdf/
No super strong reason really.
But whtmltopdf hasn't been updated since 2016 and the Phantomjs main dev have called it quits and says Headless Chrome is the future.

So I figure I might as well try to learn to work with Headless Chrome. Chrome.ahk looks like a convenient way to start for me, compared to going down the Node and Puppeteer path.

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Posted: 14 Mar 2018, 09:05
by ramonstart
Hello

Why does the Jxon_Dump method return the "menor preu00E7o do livro" value when the correct text is "menor preço do livro"?

I'm using the call below to bring the content of the list that is in the url https://www.estantevirtual.com.br/livro ... 20Kiyosaki

Would you help me?

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Posted: 16 Mar 2018, 18:23
by Shadowpheonix
Joe Glines wrote:
Shadowpheonix wrote:In the "pastebin.ahk" example that GeekDude was nice enough to include in the release package, the Tab.Call("DOM.setAttributeValue", {"nodeId": NameNode.NodeId, "name": "value", "value": "ChromeBot"}) line assigns a value to an input field. How would I go about retrieving the value after it was assigned?
I don't have an example I can post right now but I "solved this" by inserting Java script.

If you happen to come up with an example you can post, it would be most appreciated. :D

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Posted: 16 Mar 2018, 18:34
by Joe Glines
Shadowpheonix wrote:If you happen to come up with an example you can post, it would be most appreciated. :D
I'll try and work on it this weekend. I was in the middle of converting all of my examples to functions (so they'd be easy to adapt) when I got busy...

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Posted: 17 Mar 2018, 14:21
by Joe Glines
Okay, I created a function which should help some people (noobs). It leverages GeekDude's Chrome class.

You can get the function here

And this is a video walking through how to use it. It isn't great, but will help some people get their feet wet. :D

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Posted: 18 Mar 2018, 22:07
by fenchai
Is there any reason everytime chrome opens, it shows something about windows defender wanting to reset my chrome preferences and adobe and google drive keep wanting to install? this is weird. :shock:

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Posted: 19 Mar 2018, 12:37
by Shadowpheonix
Joe Glines wrote:Okay, I created a function which should help some people (noobs). It leverages GeekDude's Chrome class.

You can get the function here

And this is a video walking through how to use it. It isn't great, but will help some people get their feet wet. :D
This function definitely has a lower learning curve to it than Tab.Call() and Tab.Evaluate() for writing values. Thank you for posting it. :bravo:

However, this still leaves me clueless as to how to read an existing value from a web page in Chrome without having to install Selenium. :lol:

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Posted: 19 Mar 2018, 12:42
by Shadowpheonix
fenchai wrote:Is there any reason everytime chrome opens, it shows something about windows defender wanting to reset my chrome preferences and adobe and google drive keep wanting to install? this is weird. :shock:
This sounds like a problem with either your Chrome profile or with an extension/plugin you have installed in Chrome.
If you haven't already done so, try running with a brand new profile in Chrome and see if the issue still occurs. I am not sure what else to suggest if that fails.