[Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No IE!

Post your working scripts, libraries and tools for AHK v1.1 and older
Milchmann
Posts: 112
Joined: 05 Nov 2016, 08:50

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

Post by Milchmann » 30 Sep 2021, 12:41

Thanks for the link. I really hope we can test and use this soon.

20170201225639
Posts: 144
Joined: 01 Feb 2017, 22:57

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

Post by 20170201225639 » 03 Oct 2021, 15:56

@teadrinker Should LightJson also escape special chars in keys? I was using LightJson.stringify to serialize an AHK object with keys having unusal like: "lalt+\" (representing a shortcut), and the output isn't correct. I believe JSON standard allows any string to be keys.

But of course, there's always whether the extra escaping is worth the performance tradeoff ...

teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

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

Post by teadrinker » 04 Oct 2021, 05:17

@20170201225639
I think you are right, this is a flaw. Fixed:

Code: Select all

obj := {"a + \": "a + \", "b + /": {"a + \": "a + \"}}
MsgBox, % json := LightJson.Stringify(obj, "   ")

obj := LightJson.Parse(json)
MsgBox, % obj["b + /", "a + \"]

class LightJson
{
   static JS := LightJson.GetJS(), true := {}, false := {}, null := {}
   
   Parse(json, _rec := false) {
      if !_rec
         obj := this.Parse(this.JS.JSON.parse(json), true)
      else if !IsObject(json)
         obj := json
      else if this.JS.Object.prototype.toString.call(json) == "[object Array]" {
         obj := []
         Loop % json.length
            obj.Push( this.Parse(json[A_Index - 1], true) )
      }
      else {
         obj := {}
         keys := this.JS.Object.keys(json)
         Loop % keys.length {
            k := keys[A_Index - 1]
            obj[k] := this.Parse(json[k], true)
         }
      }
      Return obj
   }
   
   Stringify(obj, indent := "") {
      if indent|1 {
         for k, v in ["true", "false", "null"]
            if (obj = this[v])
               Return v

         if IsObject( obj ) {
            isArray := true
            for key in obj {
               if IsObject(key)
                  throw Exception("Invalid key")
               if !( key = A_Index || isArray := false )
                  break
            }
            for k, v in obj
               str .= ( A_Index = 1 ? "" : "," ) . ( isArray ? "" : this.Stringify(k, true) . ":" ) . this.Stringify(v, true)

            Return str = "" ? "{}" : isArray ? "[" . str . "]" : "{" . str . "}"
         }
         else if !(obj*1 = "" || RegExMatch(obj, "^-?0|\s"))
            Return obj
         
         for k, v in [["\", "\\"], [A_Tab, "\t"], ["""", "\"""], ["/", "\/"], ["`n", "\n"], ["`r", "\r"], [Chr(12), "\f"], [Chr(8), "\b"]]
            obj := StrReplace( obj, v[1], v[2] )

         Return """" obj """"
      }
      sObj := this.Stringify(obj, true)
      Return this.JS.eval("JSON.stringify(" . sObj . ",'','" . indent . "')")
   }
   
   GetJS() {
      static Doc, JS
      if !Doc {
         Doc := ComObjCreate("htmlfile")
         Doc.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=9"">")
         JS := Doc.parentWindow
         ( Doc.documentMode < 9 && JS.execScript() )
      }
      Return JS
   }
}

20170201225639
Posts: 144
Joined: 01 Feb 2017, 22:57

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

Post by 20170201225639 » 04 Oct 2021, 23:16

Wow, thanks for the quick update @teadrinker !

jekko1976
Posts: 97
Joined: 10 Oct 2014, 07:03

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

Post by jekko1976 » 07 Oct 2021, 09:43

Hello, I am trying to access this node:

<input aria-label="foo" maxlength="10" autocomplete="off" type="text" class="input_input__2qx3X form-control" aria-invalid="false" value="">

using @Geekdude 's trick (I am a really newbie javascript programmer):

[].filter.call(document.querySelectorAll('input'), (e) => e.aria-label.match('foo'))[0]

unfortunately the trick doesn't work (even in the devtools console mode) because "aria-label" contain a minus sign inside of it.

How can I refeer to this kind of node?
Thank you so much

EDIT: SOLVED!
The line below does the trick

[].filter.call(document.querySelectorAll('input'), (e) => e.ariaLabel.match('foo'))[0]

autu
Posts: 17
Joined: 04 Apr 2015, 11:09

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

Post by autu » 25 Oct 2021, 02:41

geek wrote:
16 Jan 2018, 17:38
Chrome.ahk

Automate Google Chrome using native AutoHotkey.


Watch the full playlist on YouTube

How it works

[...]
Pretty cool, I'll also have a play with it.

Gh0sTG0
Posts: 55
Joined: 25 Jun 2018, 07:58

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

Post by Gh0sTG0 » 27 Nov 2021, 04:06

Hi. Can I use chrome.ahk to move content in the window? I mean this, don't know how to name it correct:
2021-11-27_11-32-23.png
2021-11-27_11-32-23.png (5.84 KiB) Viewed 6688 times

User avatar
kagato
Posts: 10
Joined: 04 Dec 2015, 16:48
Location: 127.0.0.1

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

Post by kagato » 14 Dec 2021, 23:08

So I was doing some investigating with an issue that popped up, and noticed when I browse to localhost:9222, I get this message:
Image

Will this have any impact on the ability to interact with Chrome? From the way the way it's worded in the subsequent link, I can't tell if the /json data will still be leveraged but you just won't be able to navigate to the URL in the browser?
Chuck Norris doesn't need garbage collection because he doesn't call .Dispose(), he calls .DropKick().

geek
Posts: 1052
Joined: 02 Oct 2013, 22:13
Location: GeekDude
Contact:

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

Post by geek » 22 Jan 2022, 13:48

kagato wrote:
14 Dec 2021, 23:08
So I was doing some investigating with an issue that popped up, and noticed when I browse to localhost:9222, I get this message:
Image

Will this have any impact on the ability to interact with Chrome? From the way the way it's worded in the subsequent link, I can't tell if the /json data will still be leveraged but you just won't be able to navigate to the URL in the browser?
I do agree that is the case, though I haven't reviewed any more information on the subject than you have.

User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

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

Post by Xeo786 » 27 Jan 2022, 03:44

kagato wrote:
14 Dec 2021, 23:08
So I was doing some investigating with an issue that popped up, and noticed when I browse to localhost:9222, I get this message:
Image

Will this have any impact on the ability to interact with Chrome? From the way the way it's worded in the subsequent link, I can't tell if the /json data will still be leveraged but you just won't be able to navigate to the URL in the browser?
According to following comment from above issue: https://bugs.chromium.org/p/chromium/issues/detail?id=1232509
Image
They will not remove Puppeteer support as Puppeteer uses webSocketDebuggerUrl resolved by url: LocalHost:9222/json/list to control chrome
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

Milchmann
Posts: 112
Joined: 05 Nov 2016, 08:50

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

Post by Milchmann » 28 Jan 2022, 03:53

Tre4shunter wrote:
29 Sep 2021, 12:53
@Milchmann ,

afaik there are a few people (Including the G33k himself) working on modifying the lib to use websockets without IE.

Check this thread out:
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=94895&p=421942#p421942
Unfortunately, at the link seems to stand the development. :shock:
Does anyone have another idea?

Thanks

User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

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

Post by Xeo786 » 28 Jan 2022, 07:14

Milchmann wrote:
28 Jan 2022, 03:53
Tre4shunter wrote:
29 Sep 2021, 12:53
@Milchmann ,

afaik there are a few people (Including the G33k himself) working on modifying the lib to use websockets without IE.

Check this thread out:
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=94895&p=421942#p421942
Unfortunately, at the link seems to stand the development. :shock:
Does anyone have another idea?

Thanks
Chrome.ahk using websocket client from IE activeX, and there is no IE in windows 11 but activeX is available and I haven't check but chrome.ahk should work fine,

I am also sure GeekDude is working on Websocket client.
I have also tried different ways to get a solid Websocket client class which can support Chrome.ahk the link you posted above can make single Websocket connection if you deep dive into it, you find reasons why,

There is also a Websocket client lib written in 100% AHK by Shadownrun based on socket.ahk also by geek dude,
here is the link https://github.com/gustavooavila/Autohotkey-Websocket-Client

I tried to merge this Shadownrun's WS client into chrome.ahk and it worked for short messages, I find Shadownrun's WS client unable to parse/ process fragmented messages due to wrong opcode and fin bit issue, I am into different projects that's why I gave up until I finish those projects. or may be its beyond my understanding, coz I have read through whole RFC https://datatracker.ietf.org/doc/html/rfc6455 spent hours of debugging.
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

Milchmann
Posts: 112
Joined: 05 Nov 2016, 08:50

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

Post by Milchmann » 02 Feb 2022, 01:37

Thank you for your efforts. I still hope that there will be an alternative in the future, without IE support.
Otherwise I can't use the chrome.ahk anymore.

Are there any other options to Chrome.ahk to work with Chrome? I have neither admin rights nor IE support at work. What works fine so far (until Chrome version 88.0) is viewtopic.php?f=7&t=32323#p150532. That's why I have the Chrome version frozen at the state.

But in the new versions of Chrome there are now windows that are no longer displayed in the old version of Chrome. In perspective, I can only use the current versions.

Thanks

Bert

Translated with www.DeepL.com/Translator (free version)

User avatar
Gio
Posts: 1247
Joined: 30 Sep 2013, 10:54
Location: Brazil

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

Post by Gio » 02 Feb 2022, 17:43

Hello there!

Thanks for the library @geek , i am trying to use it to replace IE COM code in some of my scripts (since IE doesn't work in Windows 11).


However i am getting a security error screen when trying to connect to a chrome instance using Chrome.getpage()

Spoiler

:arrow: Is this also a Windows 11 problem? Does anyone have any ideas on how to solve this?

burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

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

Post by burque505 » 02 Feb 2022, 17:54

@Gio, I still sometimes get that error script errors (not sure about the security error). Does it do that for all pages? EDIT: I don't have Windows 11, though. Windows 10.
Regards,
burque505

User avatar
Gio
Posts: 1247
Joined: 30 Sep 2013, 10:54
Location: Brazil

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

Post by Gio » 02 Feb 2022, 18:52

Hi @burque505, thanks for the reply.

Yes, it happens even if i try to connect while chrome is displaying some other page. I can't even use the library at all since the issue occurs at the beginning of the chrome code.

I also forgot to mention that i have already tried modifying chromes default path to add --remote-debugging-port=9222 (to no avail).

malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

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

Post by malcev » 02 Feb 2022, 21:12

Read first page of the topic.

User avatar
Gio
Posts: 1247
Joined: 30 Sep 2013, 10:54
Location: Brazil

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

Post by Gio » 03 Feb 2022, 09:17

@malcev thank you, the post below solved the issue.
geek wrote:
21 Jan 2018, 12:08
You can disable this block (not sure how this effects general security of IE) by following the steps in this StackOverflow post.

dbareis
Posts: 39
Joined: 04 Feb 2022, 17:57

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

Post by dbareis » 09 Feb 2022, 00:40

The following snippet works:

Code: Select all

	PageInstance := ChromeInst.GetPageBy("url", "https://recordsearch.naa.gov.au", "startswith")
	PageInstance.Evaluate("alert('Got page by URL!');")
However that tab's page content isn't visible, how do I bring that tab into focus so you can see the alert or more specifically anything I do in that page.

gregster
Posts: 8916
Joined: 30 Sep 2013, 06:48

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

Post by gregster » 09 Feb 2022, 01:27

dbareis wrote:
09 Feb 2022, 00:40
The following snippet works:

Code: Select all

	PageInstance := ChromeInst.GetPageBy("url", "https://recordsearch.naa.gov.au", "startswith")
	PageInstance.Evaluate("alert('Got page by URL!');")
However that tab's page content isn't visible, how do I bring that tab into focus so you can see the alert or more specifically anything I do in that page.
Try

Code: Select all

PageInstance.Call("Page.bringToFront")

Post Reply

Return to “Scripts and Functions (v1)”