chrome.ahk event callback not working?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Bugz000
Posts: 93
Joined: 30 Sep 2013, 10:01

chrome.ahk event callback not working?

Post by Bugz000 » 24 Sep 2022, 20:42

Code: Select all

#singleinstance, force
setbatchlines -1
fileread, js, code.js
fileread, fjson, json.json
json := new json()
arr := json.load(fjson)
chromepath:="C:\Program Files\Google\Chrome\Application\chrome.exe"
profilepath := A_scriptdir "/chrom22"
FileCreateDir, chrom22
Chrome := new chrome(profilePath,"https://website.com/","--remote-debugging-port=9222 --enable-logging --v=1 --log-level=0",chromePath)
sleep 6000
page := chrome.getPage(,,Func("Callback").Bind())
page.Call("Log.Enable")
page.waitForLoad()
sleep 2000
msgbox % Page.evaluate(js)
ExitApp

Callback(event){
	GLOBAL
	;Listen for messages with your specific message and do an action
	msgbox % st_printarr(event)
	if (Event.Method = "Console.messageAdded") {
		msgbox % Event.params.message.text
	}
	else if (Event.Method = "Inspector.Detached"){
		ChromeInst.Kill()
		exitapp
	}
}

#include chrome.ahk
#include json.ahk
#include printarr.ahk
hey, i am using geekdudes chrome.ahk to manipulate a website, i have written some js to run on the page which works great - but i'd like to somehow get information back FROM the javascript to ahk directly, i could output to a file and have ahk watch the same file but that's nasty- is this really the only way? i've tried a few flags and callback etc i just can't seem to get anything coherent out of it, i'm clearly doing something wrong so i hope someone can shed some light on what it is
Last edited by Bugz000 on 25 Sep 2022, 20:24, edited 1 time in total.
Image
||-------[-HP-ML350E-G8-]-------||-[-32-core-xeon-]-||--[-48gb-ECC-]--||
||----[-Dell-Poweredge-r610-]---||-[-16-core-xeon-]-||--[-16gb-ECC-]--||
||-[-Lenovo-ThinkPad-x201-tab-]-||---[-4-core-i7-]--||-[-8gb-nonECC-]-||
||---------------------------[-shack--img-]---------------------------||

User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: chrome.ahk pull console.log() back to ahk?

Post by Xtra » 24 Sep 2022, 21:58

Code: Select all

msgbox % var := Page.evaluate(js).Value
?

User avatar
Bugz000
Posts: 93
Joined: 30 Sep 2013, 10:01

Re: chrome.ahk pull console.log() back to ahk?

Post by Bugz000 » 24 Sep 2022, 22:17

Xtra wrote:
24 Sep 2022, 21:58

Code: Select all

msgbox % var := Page.evaluate(js).Value
?
could you possibly elaborate please?
Image
||-------[-HP-ML350E-G8-]-------||-[-32-core-xeon-]-||--[-48gb-ECC-]--||
||----[-Dell-Poweredge-r610-]---||-[-16-core-xeon-]-||--[-16gb-ECC-]--||
||-[-Lenovo-ThinkPad-x201-tab-]-||---[-4-core-i7-]--||-[-8gb-nonECC-]-||
||---------------------------[-shack--img-]---------------------------||

User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: chrome.ahk pull console.log() back to ahk?

Post by Xtra » 24 Sep 2022, 22:21

That's how i get returned data back from running js.
I have not had to use the console yet.

HTH

User avatar
Bugz000
Posts: 93
Joined: 30 Sep 2013, 10:01

Re: chrome.ahk pull console.log() back to ahk?

Post by Bugz000 » 25 Sep 2022, 19:08

no, it does not help i'm afraid, you're missing out literally all context, you've thrown a line of code and said "i use this" - that's fantastic but is it getting the return of a function call? a variable? i don't understand what you're telling me whatsoever or how it relates to using the callback func to get the console stream
without this context i've no idea how the js side of this would look either - i have literally no clue what you are trying to express.
You need to be more specific, like, orders of magnitude more specific.

Xtra wrote:
24 Sep 2022, 22:21
That's how i get returned data back from running js.
I have not had to use the console yet.

HTH
Image
||-------[-HP-ML350E-G8-]-------||-[-32-core-xeon-]-||--[-48gb-ECC-]--||
||----[-Dell-Poweredge-r610-]---||-[-16-core-xeon-]-||--[-16gb-ECC-]--||
||-[-Lenovo-ThinkPad-x201-tab-]-||---[-4-core-i7-]--||-[-8gb-nonECC-]-||
||---------------------------[-shack--img-]---------------------------||

User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: chrome.ahk pull console.log() back to ahk?

Post by Xtra » 25 Sep 2022, 19:36

When i run JS from chrome.ahk and that JS is returning data that is how i get it.
I do not know what your JS is or what it does.

Maybe someone else has an idea that can help you.

Sorry for any confusion.
-GL

User avatar
Bugz000
Posts: 93
Joined: 30 Sep 2013, 10:01

Re: chrome.ahk pull console.log() back to ahk?

Post by Bugz000 » 25 Sep 2022, 19:41

i hope so too. :eh:
Image
||-------[-HP-ML350E-G8-]-------||-[-32-core-xeon-]-||--[-48gb-ECC-]--||
||----[-Dell-Poweredge-r610-]---||-[-16-core-xeon-]-||--[-16gb-ECC-]--||
||-[-Lenovo-ThinkPad-x201-tab-]-||---[-4-core-i7-]--||-[-8gb-nonECC-]-||
||---------------------------[-shack--img-]---------------------------||

User avatar
Bugz000
Posts: 93
Joined: 30 Sep 2013, 10:01

Re: chrome.ahk pull console.log() back to ahk?

Post by Bugz000 » 25 Sep 2022, 20:17

image.png
image.png (75.18 KiB) Viewed 719 times
my example utilises these, taken from the event callback example within geekdudes example repo... https://raw.githubusercontent.com/G33kDude/Chrome.ahk/master/Examples/EventCallbacks.ahk

my question was very simple, why it was not working
Image
||-------[-HP-ML350E-G8-]-------||-[-32-core-xeon-]-||--[-48gb-ECC-]--||
||----[-Dell-Poweredge-r610-]---||-[-16-core-xeon-]-||--[-16gb-ECC-]--||
||-[-Lenovo-ThinkPad-x201-tab-]-||---[-4-core-i7-]--||-[-8gb-nonECC-]-||
||---------------------------[-shack--img-]---------------------------||

User avatar
Bugz000
Posts: 93
Joined: 30 Sep 2013, 10:01

Re: chrome.ahk event callback not working?

Post by Bugz000 » 26 Sep 2022, 16:39

nobody?
Image
||-------[-HP-ML350E-G8-]-------||-[-32-core-xeon-]-||--[-48gb-ECC-]--||
||----[-Dell-Poweredge-r610-]---||-[-16-core-xeon-]-||--[-16gb-ECC-]--||
||-[-Lenovo-ThinkPad-x201-tab-]-||---[-4-core-i7-]--||-[-8gb-nonECC-]-||
||---------------------------[-shack--img-]---------------------------||

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

Re: chrome.ahk event callback not working?

Post by malcev » 26 Sep 2022, 22:23

For me example from G33kDude works.
But read from here:
viewtopic.php?p=408954#p408954

Post Reply

Return to “Ask for Help (v1)”