How To Get Var Value From JS To AHK? [Rufaydium]

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
ositoMalvado
Posts: 183
Joined: 24 Dec 2019, 12:02
Contact:

How To Get Var Value From JS To AHK? [Rufaydium]

Post by ositoMalvado » 29 Jun 2022, 20:25

Hi guys ! Need help here, i need to get a variable value from JS to AHK, using rufaydium

I want to take "300" value from "thisvar" var into AHK

for example

Code: Select all

sesion.ExecuteSync('thisvar=300') ; >>>I WANT TO CREATE js VAR FROM AHK TOO, SO NEED BELOW LINE WORKs WITH THIS assignment.
Msgbox, % sesion.Var("thisvar") ; >>>THIS AN EXAMPLE WHAT I WANT TO DO - i want to msgbox "300" here, how can i do it?

THANKS GUYS FOR READ/HELP :wave:
My WEB some useful stuff

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

Re: HOW TO GET VAR VALUE FROM JS TO AHK? [Rufaydium]

Post by Xeo786 » 30 Jun 2022, 04:32

ositoMalvado wrote:
29 Jun 2022, 20:25
Hi guys ! Need help here, i need to get a variable value from JS to AHK, using rufaydium

I want to take "300" value from "thisvar" var into AHK

for example

Code: Select all

sesion.ExecuteSync('thisvar=300') ; >>>I WANT TO CREATE js VAR FROM AHK TOO, SO NEED BELOW LINE WORKs WITH THIS assignment.
Msgbox, % sesion.Var("thisvar") ; >>>THIS AN EXAMPLE WHAT I WANT TO DO - i want to msgbox "300" here, how can i do it?

THANKS GUYS FOR READ/HELP :wave:
you should use " instead ', you can try following code

Code: Select all

session.ExecuteSync("thisvar = 300")
msgbox, % session.ExecuteSync("return thisvar")
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

User avatar
ositoMalvado
Posts: 183
Joined: 24 Dec 2019, 12:02
Contact:

Re: HOW TO GET VAR VALUE FROM JS TO AHK? [Rufaydium]

Post by ositoMalvado » 30 Jun 2022, 15:47

Xeo786 wrote:
30 Jun 2022, 04:32
Thanks for the answer, but It doesnt work for me, look at this.

Code: Select all

global firefox:=new Rufaydium("geckodriver.exe")
global sesion:=firefox.NewSession("C:\Program Files\Mozilla Firefox\firefox.exe")
sesion.Navigate("https://www.google.com.ar")
sesion.WaitForLoad()
sesion.ExecuteSync("asd=300;alert(asd);")
;this alert works well
msgbox, % sesion.ExecuteASync("return asd")
;i cant acces to 'asd' var from ahk, how can i do it?
My WEB some useful stuff

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

Re: HOW TO GET VAR VALUE FROM JS TO AHK? [Rufaydium]

Post by Xeo786 » 01 Jul 2022, 03:22

ositoMalvado wrote:
30 Jun 2022, 15:47
Xeo786 wrote:
30 Jun 2022, 04:32
Thanks for the answer, but It doesnt work for me, look at this.

Code: Select all

global firefox:=new Rufaydium("geckodriver.exe")
global sesion:=firefox.NewSession("C:\Program Files\Mozilla Firefox\firefox.exe")
sesion.Navigate("https://www.google.com.ar")
sesion.WaitForLoad()
sesion.ExecuteSync("asd=300;alert(asd);")
;this alert works well
msgbox, % sesion.ExecuteASync("return asd")
;i cant acces to 'asd' var from ahk, how can i do it?
Following methods are not needed / wrong, as Rufaydium accesses the browser synchronously, it waits for the page to finish loading page there proceeds to the next step, and same goes for ExecuteASync

1) sesion.WaitForLoad()
2) sesion.ExecuteASync("return asd")
3) I suspect Alert() intrups JS

I tested the following code and its working

Code: Select all

#include Rufaydium.ahk
URL := "https://www.autohotkey.com/boards/viewtopic.php?p=470577#p470577"
Page := GetRufaydium(URL)
Page.ExecuteSync("asd=300")
msgbox, % Page.ExecuteSync("return asd")
exitapp

; GetRufaydium(URL) gets existing session  
; stops us creatting multiple sessions again and again 
; make sure do not manually close driver / chrome.driver.exit()
; by Xeo786
GetRufaydium(URL)
{
	; get chrome driver / runs chrome driver if not running, download driver if available in A_ScriptDir
	; Run Chrome Driver with default parameters and loads default capabilities
	Chrome := new Rufaydium() 
	Page := Chrome.getSessionByUrl(URL) ; check page (created by driver) if already exist 
	if !isobject(page) ; checcking if Session with url exist
	{
		Page := Chrome.getSession(1,1) ; try getting first session first tab
		if isobject(page) ; if exist 
			Page.NewTab() ; create new tab instead new session
		else ; if does not exist 
			Page := Chrome.NewSession() ; create new session ; Page.Exit() if any session manually closed by user which causes lag
		Page.Navigate(URL) ; navigate		
	}
	return page 
}
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

Post Reply

Return to “Ask for Help (v1)”