Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
Xeo786
Posts: 766
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

17 Dec 2022, 00:33

Flowgun wrote:
16 Dec 2022, 13:40
@Xeo786
Thank you for your input and suggestion.

I tried using different drivers at different locations for each profile in the past, and I still got the error. I think that different profiles just require different User data dir to work correctly.
Having to create a different User Data dir adds a lot of friction. I want the experience to be as seamless as possible for the user, being able to open his profiles either with Rufaydium or the regular way.
If they move their other profile data dir to another location on disk, chrome would detect it I presume, and won't be able to open it the regular way. Since the folders can also get big, recopying and moving them each time to update is not a viable solution.
I will investigate this further whenever I find the time.
It's a chromedriver bug people have already reported that.
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
yousef_badr23
Posts: 19
Joined: 26 Aug 2022, 07:18

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

19 Dec 2022, 05:42

When trying to get the size or location of any element in chrome, I get the following error:
Size: {"error":"unknown command","message":"unknown command: Cannot call non W3C standard command while in W3C mode","stacktrace":"Backtrace:\n\tOrdinal0 [0x004FACD3+2075859]\n\tOrdinal0 [0x0048EE61+1633889]\n\tOrdinal0 [0x0038B7BD+571325]\n\tOrdinal0 [0x003B008C+721036]\n\tOrdinal0 [0x003B0F3F+724799]\n\tGetHandleVerifier [0x007AEED2+2769538]\n\tGetHandleVerifier [0x007A0D95+2711877]\n\tGetHandleVerifier [0x0058A03A+521194]\n\tGetHandleVerifier [0x00588DA0+516432]\n\tOrdinal0 [0x0049682C+1665068]\n\tOrdinal0 [0x0049B128+1683752]\n\tOrdinal0 [0x0049B215+1683989]\n\tOrdinal0 [0x004A6484+1729668]\n\tBaseThreadInitThunk [0x75E0FEF9+25]\n\tRtlGetAppContainerNamedObjectPath [0x77507BBE+286]\n\tRtlGetAppContainerNamedObjectPath [0x77507B8E+238]\n"}

Location: {"error":"unknown command","message":"unknown command: Cannot call non W3C standard command while in W3C mode","stacktrace":"Backtrace:\n\tOrdinal0 [0x004FACD3+2075859]\n\tOrdinal0 [0x0048EE61+1633889]\n\tOrdinal0 [0x0038B7BD+571325]\n\tOrdinal0 [0x003B008C+721036]\n\tOrdinal0 [0x003B0F3F+724799]\n\tGetHandleVerifier [0x007AEED2+2769538]\n\tGetHandleVerifier [0x007A0D95+2711877]\n\tGetHandleVerifier [0x0058A03A+521194]\n\tGetHandleVerifier [0x00588DA0+516432]\n\tOrdinal0 [0x0049682C+1665068]\n\tOrdinal0 [0x0049B128+1683752]\n\tOrdinal0 [0x0049B215+1683989]\n\tOrdinal0 [0x004A6484+1729668]\n\tBaseThreadInitThunk [0x75E0FEF9+25]\n\tRtlGetAppContainerNamedObjectPath [0x77507BBE+286]\n\tRtlGetAppContainerNamedObjectPath [0x77507B8E+238]\n"}

LocationInView: {"error":"unknown command","message":"unknown command: Cannot call non W3C standard command while in W3C mode","stacktrace":"Backtrace:\n\tOrdinal0 [0x004FACD3+2075859]\n\tOrdinal0 [0x0048EE61+1633889]\n\tOrdinal0 [0x0038B7BD+571325]\n\tOrdinal0 [0x003B008C+721036]\n\tOrdinal0 [0x003B0F3F+724799]\n\tGetHandleVerifier [0x007AEED2+2769538]\n\tGetHandleVerifier [0x007A0D95+2711877]\n\tGetHandleVerifier [0x0058A03A+521194]\n\tGetHandleVerifier [0x00588DA0+516432]\n\tOrdinal0 [0x0049682C+1665068]\n\tOrdinal0 [0x0049B128+1683752]\n\tOrdinal0 [0x0049B215+1683989]\n\tOrdinal0 [0x004A6484+1729668]\n\tBaseThreadInitThunk [0x75E0FEF9+25]\n\tRtlGetAppContainerNamedObjectPath [0x77507BBE+286]\n\tRtlGetAppContainerNamedObjectPath [0x77507B8E+238]\n"}
in firefox, I get an empty json.
Is this normal behavior?
User avatar
Xeo786
Posts: 766
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

19 Dec 2022, 06:10

yousef_badr23 wrote:
19 Dec 2022, 05:42
When trying to get the size or location of any element in chrome, I get the following error:
Size: {"error":"unknown command","message":"unknown command: Cannot call non W3C standard command while in W3C mode","stacktrace":"Backtrace:\n\tOrdinal0 [0x004FACD3+2075859]\n\tOrdinal0 [0x0048EE61+1633889]\n\tOrdinal0 [0x0038B7BD+571325]\n\tOrdinal0 [0x003B008C+721036]\n\tOrdinal0 [0x003B0F3F+724799]\n\tGetHandleVerifier [0x007AEED2+2769538]\n\tGetHandleVerifier [0x007A0D95+2711877]\n\tGetHandleVerifier [0x0058A03A+521194]\n\tGetHandleVerifier [0x00588DA0+516432]\n\tOrdinal0 [0x0049682C+1665068]\n\tOrdinal0 [0x0049B128+1683752]\n\tOrdinal0 [0x0049B215+1683989]\n\tOrdinal0 [0x004A6484+1729668]\n\tBaseThreadInitThunk [0x75E0FEF9+25]\n\tRtlGetAppContainerNamedObjectPath [0x77507BBE+286]\n\tRtlGetAppContainerNamedObjectPath [0x77507B8E+238]\n"}
Error says Rufaydium is calling non W3C standard API, Thanks for pointing out I have just removed them, you can use .rect Element.Rect() it will return with location and size

Code: Select all

msgbox, % json.dump(Element.Rect(),1)
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
DrX
Posts: 5
Joined: 14 Jul 2018, 07:24

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

19 Dec 2022, 17:06

Hello, I'm trying to get some understanding of classes using Rufaydium for a small project I have.

I'm having trouble retrieving the Chrome and ahkPage properties inside the methods, can someone please point me to what I'm doing wrong?

Code: Select all

#Requires AutoHotkey v1.1
#NoEnv
#SingleInstance, Force
SendMode, Input
SetBatchLines, -1
SetWorkingDir, %A_ScriptDir%
;#Warn

#Include include\Rufaydium\Rufaydium.ahk

F1::Scrape.goPage()
F12::Scrape.Quit()

class Scrape
{

    Chrome  := new Rufaydium("chromedriver.exe")
    ahkPage := "https://www.autohotkey.com"


    goPage()
    {
        ;this.Chrome := new Rufaydium("chromedriver.exe")
        page := this.Chrome.NewSession()
        page.Navigate(this.ahkPage)
        return
    }


    Quit()
    {
        this.Chrome.QuitAllSessions()
        this.Chrome.Driver.Exit()
        return
    }

}
Thank you
User avatar
Xeo786
Posts: 766
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

19 Dec 2022, 23:40

DrX wrote:
19 Dec 2022, 17:06
Hello, I'm trying to get some understanding of classes using Rufaydium for a small project I have.

I'm having trouble retrieving the Chrome and ahkPage properties inside the methods, can someone please point me to what I'm doing wrong?

Code: Select all

#Requires AutoHotkey v1.1
#NoEnv
#SingleInstance, Force
SendMode, Input
SetBatchLines, -1
SetWorkingDir, %A_ScriptDir%
;#Warn

#Include include\Rufaydium\Rufaydium.ahk

F1::Scrape.goPage()
F12::Scrape.Quit()

class Scrape
{

    Chrome  := new Rufaydium("chromedriver.exe")
    ahkPage := "https://www.autohotkey.com"


    goPage()
    {
        ;this.Chrome := new Rufaydium("chromedriver.exe")
        page := this.Chrome.NewSession()
        page.Navigate(this.ahkPage)
        return
    }


    Quit()
    {
        this.Chrome.QuitAllSessions()
        this.Chrome.Driver.Exit()
        return
    }

}
This Post is dedicated to Rufaydium, You can ask for classes-dedicated posts, I suggest you should start with "Classes in AHK, Basic tutorial." or links mentioned here

The method .goPage() is creating new session everytime, and Quit() will exit all session the driver, you can turn Chrome & ahkpagestatic variable
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
DrX
Posts: 5
Joined: 14 Jul 2018, 07:24

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

20 Dec 2022, 20:47

Thank you for your reply sir.

I'm also wondering what the correct way to retrieve all links in a webpage? This seems to return empty

Code: Select all

[spoiler2=]
		Chrome := new Rufaydium("chromedriver.exe")
		Page := Chrome.NewSession()

		Page.Navigate("https://www.autohotkey.com")
		Page.CDP.WaitForLoad()

		Links := Page.getElementsbyTagName("a")
		MsgBox, % Links
		Return
[/spoiler2]
User avatar
Xeo786
Posts: 766
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

21 Dec 2022, 00:47

DrX wrote:
20 Dec 2022, 20:47
I'm also wondering what the correct way to retrieve all links in a webpage? This seems to return empty
This is how you can get all the href idk if it would work for src too.

Code: Select all

Chrome := new Rufaydium()
Page := Chrome.NewSession()
Page.URL := "https://www.autohotkey.com/boards/viewtopic.php?f=6&t=102616&start=460"
elements := Page.findelements(By.Plinktext,"")
for i, e in elements
{
    msgbox, % e.outerHtml "`n`nsrc:" e.src "`nhref:" e.href
}
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
Sadaosh1970
Posts: 19
Joined: 29 Nov 2022, 06:52

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

21 Dec 2022, 17:25

Hello @Xeo786
I have a doubt.
Is there any way to get the page id in Firefox?

I used

Code: Select all

Page.id
, but the returned id was: "ba1faf2b-4625-4ec7-9745-7fd1982b7296" (Main process target).

Is there any way to get the id of the active page otherwise without using the commands, RegExMatch and StrSplit over json.dump(Page.Detail(),1)?

json

Code: Select all

[
	{
		"description": "",
		"devtoolsFrontendUrl": null,
		"faviconUrl": "",
		"id": "293b2164-b3c4-49fb-b3ec-747386613224",
		"type": "page",
		"url": "https://www.mozilla.org/pt-BR/",
		"webSocketDebuggerUrl": "ws://127.0.0.1:9222/devtools/page/293b2164-b3c4-49fb-b3ec-747386613224"
	},
	{
		"description": "Main process target",
		"devtoolsFrontendUrl": "",
		"faviconUrl": "",
		"id": "ba1faf2b-4625-4ec7-9745-7fd1982b7296",
		"title": "Main process target",
		"type": "browser",
		"url": "",
		"webSocketDebuggerUrl": "ws://127.0.0.1:9222/devtools/browser/ba1faf2b-4625-4ec7-9745-7fd1982b7296"
	},
	{
		"description": "",
		"devtoolsFrontendUrl": null,
		"faviconUrl": "",
		"id": "a89d417c-d038-445f-b259-5544fd439278",
		"type": "page",
		"url": "https://www.mozilla.org/pt-BR/about/",
		"webSocketDebuggerUrl": "ws://127.0.0.1:9222/devtools/page/a89d417c-d038-445f-b259-5544fd439278"
	},
	{
		"description": "",
		"devtoolsFrontendUrl": null,
		"faviconUrl": "",
		"id": "7494d12f-e512-4ddf-9329-88f28cc4c7dc",
		"type": "page",
		"url": "https://www.mozilla.org/pt-BR/contribute/",
		"webSocketDebuggerUrl": "ws://127.0.0.1:9222/devtools/page/7494d12f-e512-4ddf-9329-88f28cc4c7dc"
	}
]
I got it, but I had to use something like the code below:

Code: Select all

id_firefox()
{

	url_firefox := Get_url() ; url active on Firefox

	for Index, current_tab in StrSplit(json.dump(Page.Detail(),1),"description"": """) ; code get here in this Forum
	{
		if Index > 1 
		{
			if InStr(current_tab,"type"": ""page""") 
			{
				; capture  id tab
				RegExMatch(current_tab, "id"": ""(.*)", id_tab, StartingPos := 1)
				id_tab := StrReplace(id_tab,"id"": ","") ; kill id": "
				id_tab := StrReplace(id_tab,"""","") ; kill "
				id_tab := StrReplace(id_tab,",","") ; kill ,
				
				; capture url 
				RegExMatch(current_tab, "url"": ""(.*)", url_tab, StartingPos := 1)
				url_tab := StrReplace(url_tab,"url"": ","") ; retira url": "
				url_tab := StrReplace(url_tab,"""","") ; retira todas as aspas
				url_tab := StrReplace(url_tab,",","") ; retira todas as vírgulas
				
				; compare
				if url_tab = %url_firefox%
				{
					return id_tab
				}
			}
		}
	}
}
User avatar
Xeo786
Posts: 766
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

22 Dec 2022, 03:18

Sadaosh1970 wrote:
21 Dec 2022, 17:25
Hello @Xeo786
I have a doubt.
Is there any way to get the page id in Firefox?
Yes.

Code: Select all

for i, obj in  Page.Detail()
	msgbox, % obj.id "`n" obj.url
Sadaosh1970 wrote:
21 Dec 2022, 17:25
Is there any way to get the id of the active page otherwise without using the commands, RegExMatch and StrSplit over json.dump(Page.Detail(),1)?
Yes....! for chrome its always first [1] ID is active page id, I am not sure about firefox, please confirm if its same for FF

Code: Select all

msgbox, % Page.Detail()[1].id
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
Sadaosh1970
Posts: 19
Joined: 29 Nov 2022, 06:52

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

22 Dec 2022, 13:33

@Xeo786

This Works!!! :D

Code: Select all

for i, obj in  Page.Detail()
msgbox, % obj.id "`n" obj.url
This Return id tab(1,1) on Firefox :(

Code: Select all

msgbox, % Page.Detail()[1].id
Sadaosh1970
Posts: 19
Joined: 29 Nov 2022, 06:52

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

23 Dec 2022, 12:15

I'm trying to capture the active url in Firefox, but still not active in Rufaydium.
I tried to use:

Code: Select all

Page.ExecuteSync("navigator.clipboard.writeText(window.location.href)")
Sometimes it works. Other times not.
Does anyone have a way to do this?
For now, I´m using: send, ^a, send, ^c
Thanks in advance!
User avatar
Xeo786
Posts: 766
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

24 Dec 2022, 02:55

Sadaosh1970 wrote:
23 Dec 2022, 12:15
I'm trying to capture the active url in Firefox, but still not active in Rufaydium.
I tried to use:

Code: Select all

Page.ExecuteSync("navigator.clipboard.writeText(window.location.href)")
Sometimes it works. Other times not.
Does anyone have a way to do this?
For now, I´m using: send, ^a, send, ^c
Thanks in advance!
:shh: here is the work around
Spoiler
now it's time to fix Page.Activetab() for firefox
Edit:
Fixed Page.Activetab() for firefox
update Rufaydium and try this one

Code: Select all

FF := new Rufaydium("geckodriver")
Page := FF.NewSession()
Page.URL := "https://www.autohotkey.com/boards/viewtopic.php?f=6&t=102616&start=460"
Page.NewTab()
Page.url := "https://www.autohotkey.com/boards/viewtopic.php?t=66204"
return

f2::
Page.Quit()
FF.Driver.Exit()
return

f1::
msgbox, % "Title: " page.title "`n`nLook at above title now manually change tab and press ok"
;page.switchbytitle(GetFFActivetitlebyPID(FF.Driver.PID))
page.ActiveTab()
msgbox, % "Title: " page.title "`n`n now rufaydium switched to active tab`n`nPress F2 to closed broswer"
return
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
Sadaosh1970
Posts: 19
Joined: 29 Nov 2022, 06:52

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

24 Dec 2022, 08:14

Dear @Xeo786:
First, thank you for your reply. Your work is fantastic!

I had already noticed another problem using Firefox that seems to have arisen since the "Commits on Dec 5, 2022" update. :problem:

I'm using Rufaydium's version of "Commits on Dec 3, 2022" and everything works normally. :D

But as of "Dec 5, 2022" versions Rufaydium was no longer able to control the Firefox browser for me. :problem:
A new Firefox session starts, but nothing happens.
The ActiveSessions.ini file looks like this": [geckodriver]
http://"

Using Rufaydium's version of "Dec 3, 2022" and the code below, everything works.

Code: Select all

#Include %A_ScriptDir%\Rufaydium\Rufaydium.ahk

FF := new Rufaydium("geckodriver")
Page := FF.NewSession()
Page.URL := "https://www.autohotkey.com/boards/viewtopic.php?f=6&t=102616&start=460"
Page.NewTab()
Page.url := "https://www.autohotkey.com/boards/viewtopic.php?t=66204"
return

f2::
Page.Quit()
FF.Driver.Exit()
return

f1::
msgbox, % "Title: " page.title "`n`nLook at above title now manually change tab and press ok"
page.switchbytitle(GetFFActivetitlebyPID(FF.Driver.PID))
msgbox, % "Title: " page.title "`n`n now Rufaydium switched to active tab`n`nPress F2 to closed browser"
return

GetFFActivetitlebyPID(PID)
{
    FFPID := GetFireFoxPID(PID)
    wingettitle, title, % "ahk_pid " FFPID
    title := strreplace(title," — Mozilla Firefox") ; "— make sure ahk is saved as uft-8 with BOM 
    return title 
}

GetFireFoxPID(PID)
{
    for proc in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process WHERE Name = 'firefox.exe'")
        if ( proc.ParentProcessId = PID)
            for proc2 in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process WHERE Name = 'firefox.exe'")
                if ( proc2.ParentProcessId = proc.processid)
                    return proc2.processid
}
return

But using the new version of Rufaydium "Commits on Dec 24, 2022" and the code below, a new Firefox session is opened, I noticed that Firefox's address bar flashes, but then nothing happens.

Code: Select all

#Include %A_ScriptDir%\Rufaydium\Rufaydium.ahk
FF := new Rufaydium("geckodriver")
Page := FF.NewSession()
Page.URL := "https://www.autohotkey.com/boards/viewtopic.php?f=6&t=102616&start=460"
Page.NewTab()
Page.url := "https://www.autohotkey.com/boards/viewtopic.php?t=66204"
return

f2::
Page.Quit()
FF.Driver.Exit()
return

f1::
msgbox, % "Title: " page.title "`n`nLook at above title now manually change tab and press ok"
;page.switchbytitle(GetFFActivetitlebyPID(FF.Driver.PID))
page.ActiveTab()
msgbox, % "Title: " page.title "`n`n now rufaydium switched to active tab`n`nPress F2 to closed broswer"
return
Thanks in advance if you can help me!
Sadaosh1970
Posts: 19
Joined: 29 Nov 2022, 06:52

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

24 Dec 2022, 11:50

Just one more doubt: :?:

If two different pages have the same title (but different urls), will Rufaydium be able to identify the active tab correctly?

Tanks in advance!
Sadaosh1970
Posts: 19
Joined: 29 Nov 2022, 06:52

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

24 Dec 2022, 12:18

I found the code below.
It returns the url of the page that is active in Firefox
I did some tests and it's working.

Is it possible to insert something similar in Rufaydium so that we can get the url of the page that is active in Firefox, since different pages can have the same title, despite having different urls? 8-)
Tank You again!!!

viewtopic.php?t=3702

Code: Select all

; AutoHotkey Version: AutoHotkey 1.1
; Language:           English
; Platform:           Win7 SP1 / Win8.1 / Win10
; Author:             Antonio Bueno <user atnbueno of Google's popular e-mail service>
; Short description:  Gets the URL of the current (active) browser tab for most modern browsers
; Last Mod:           2016-05-19

Menu, Tray, Icon, % A_WinDir "\system32\netshell.dll", 86 ; Shows a world icon in the system tray

ModernBrowsers := "ApplicationFrameWindow,Chrome_WidgetWin_0,Chrome_WidgetWin_1,Maxthon3Cls_MainFrm,MozillaWindowClass,Slimjet_WidgetWin_1"
LegacyBrowsers := "IEFrame,OperaWindowClass"

^+!u::
	nTime := A_TickCount
	sURL := GetActiveBrowserURL()
	WinGetClass, sClass, A
	If (sURL != "")
		MsgBox, % "The URL is """ sURL """`nEllapsed time: " (A_TickCount - nTime) " ms (" sClass ")"
	Else If sClass In % ModernBrowsers "," LegacyBrowsers
		MsgBox, % "The URL couldn't be determined (" sClass ")"
	Else
		MsgBox, % "Not a browser or browser not supported (" sClass ")"
Return

GetActiveBrowserURL() {
	global ModernBrowsers, LegacyBrowsers
	WinGetClass, sClass, A
	If sClass In % ModernBrowsers
		Return GetBrowserURL_ACC(sClass)
	Else If sClass In % LegacyBrowsers
		Return GetBrowserURL_DDE(sClass) ; empty string if DDE not supported (or not a browser)
	Else
		Return ""
}

; "GetBrowserURL_DDE" adapted from DDE code by Sean, (AHK_L version by maraskan_user)
; Found at http://autohotkey.com/board/topic/17633-/?p=434518

GetBrowserURL_DDE(sClass) {
	WinGet, sServer, ProcessName, % "ahk_class " sClass
	StringTrimRight, sServer, sServer, 4
	iCodePage := A_IsUnicode ? 0x04B0 : 0x03EC ; 0x04B0 = CP_WINUNICODE, 0x03EC = CP_WINANSI
	DllCall("DdeInitialize", "UPtrP", idInst, "Uint", 0, "Uint", 0, "Uint", 0)
	hServer := DllCall("DdeCreateStringHandle", "UPtr", idInst, "Str", sServer, "int", iCodePage)
	hTopic := DllCall("DdeCreateStringHandle", "UPtr", idInst, "Str", "WWW_GetWindowInfo", "int", iCodePage)
	hItem := DllCall("DdeCreateStringHandle", "UPtr", idInst, "Str", "0xFFFFFFFF", "int", iCodePage)
	hConv := DllCall("DdeConnect", "UPtr", idInst, "UPtr", hServer, "UPtr", hTopic, "Uint", 0)
	hData := DllCall("DdeClientTransaction", "Uint", 0, "Uint", 0, "UPtr", hConv, "UPtr", hItem, "UInt", 1, "Uint", 0x20B0, "Uint", 10000, "UPtrP", nResult) ; 0x20B0 = XTYP_REQUEST, 10000 = 10s timeout
	sData := DllCall("DdeAccessData", "Uint", hData, "Uint", 0, "Str")
	DllCall("DdeFreeStringHandle", "UPtr", idInst, "UPtr", hServer)
	DllCall("DdeFreeStringHandle", "UPtr", idInst, "UPtr", hTopic)
	DllCall("DdeFreeStringHandle", "UPtr", idInst, "UPtr", hItem)
	DllCall("DdeUnaccessData", "UPtr", hData)
	DllCall("DdeFreeDataHandle", "UPtr", hData)
	DllCall("DdeDisconnect", "UPtr", hConv)
	DllCall("DdeUninitialize", "UPtr", idInst)
	csvWindowInfo := StrGet(&sData, "CP0")
	StringSplit, sWindowInfo, csvWindowInfo, `" ;"; comment to avoid a syntax highlighting issue in autohotkey.com/boards
	Return sWindowInfo2
}

GetBrowserURL_ACC(sClass) {
	global nWindow, accAddressBar
	If (nWindow != WinExist("ahk_class " sClass)) ; reuses accAddressBar if it's the same window
	{
		nWindow := WinExist("ahk_class " sClass)
		accAddressBar := GetAddressBar(Acc_ObjectFromWindow(nWindow))
	}
	Try sURL := accAddressBar.accValue(0)
	If (sURL == "") {
		WinGet, nWindows, List, % "ahk_class " sClass ; In case of a nested browser window as in the old CoolNovo (TO DO: check if still needed)
		If (nWindows > 1) {
			accAddressBar := GetAddressBar(Acc_ObjectFromWindow(nWindows2))
			Try sURL := accAddressBar.accValue(0)
		}
	}
	If ((sURL != "") and (SubStr(sURL, 1, 4) != "http")) ; Modern browsers omit "http://"
		sURL := "http://" sURL
	If (sURL == "")
		nWindow := -1 ; Don't remember the window if there is no URL
	Return sURL
}

; "GetAddressBar" based in code by uname
; Found at http://autohotkey.com/board/topic/103178-/?p=637687

GetAddressBar(accObj) {
	Try If ((accObj.accRole(0) == 42) and IsURL(accObj.accValue(0)))
		Return accObj
	Try If ((accObj.accRole(0) == 42) and IsURL("http://" accObj.accValue(0))) ; Modern browsers omit "http://"
		Return accObj
	For nChild, accChild in Acc_Children(accObj)
		If IsObject(accAddressBar := GetAddressBar(accChild))
			Return accAddressBar
}

IsURL(sURL) {
	Return RegExMatch(sURL, "^(?<Protocol>https?|ftp)://(?<Domain>(?:[\w-]+\.)+\w\w+)(?::(?<Port>\d+))?/?(?<Path>(?:[^:/?# ]*/?)+)(?:\?(?<Query>[^#]+)?)?(?:\#(?<Hash>.+)?)?$")
}

; The code below is part of the Acc.ahk Standard Library by Sean (updated by jethrow)
; Found at http://autohotkey.com/board/topic/77303-/?p=491516

Acc_Init()
{
	static h
	If Not h
		h:=DllCall("LoadLibrary","Str","oleacc","Ptr")
}
Acc_ObjectFromWindow(hWnd, idObject = 0)
{
	Acc_Init()
	If DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", idObject&=0xFFFFFFFF, "Ptr", -VarSetCapacity(IID,16)+NumPut(idObject==0xFFFFFFF0?0x46000000000000C0:0x719B3800AA000C81,NumPut(idObject==0xFFFFFFF0?0x0000000000020400:0x11CF3C3D618736E0,IID,"Int64"),"Int64"), "Ptr*", pacc)=0
	Return ComObjEnwrap(9,pacc,1)
}
Acc_Query(Acc) {
	Try Return ComObj(9, ComObjQuery(Acc,"{618736e0-3c3d-11cf-810c-00aa00389b71}"), 1)
}
Acc_Children(Acc) {
	If ComObjType(Acc,"Name") != "IAccessible"
		ErrorLevel := "Invalid IAccessible Object"
	Else {
		Acc_Init(), cChildren:=Acc.accChildCount, Children:=[]
		If DllCall("oleacc\AccessibleChildren", "Ptr",ComObjValue(Acc), "Int",0, "Int",cChildren, "Ptr",VarSetCapacity(varChildren,cChildren*(8+2*A_PtrSize),0)*0+&varChildren, "Int*",cChildren)=0 {
			Loop %cChildren%
				i:=(A_Index-1)*(A_PtrSize*2+8)+8, child:=NumGet(varChildren,i), Children.Insert(NumGet(varChildren,i-8)=9?Acc_Query(child):child), NumGet(varChildren,i-8)=9?ObjRelease(child):
			Return Children.MaxIndex()?Children:
		} Else
			ErrorLevel := "AccessibleChildren DllCall Failed"
	}
}
User avatar
Xeo786
Posts: 766
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

26 Dec 2022, 03:14

Sadaosh1970 wrote:
24 Dec 2022, 12:18
Is it possible to insert something similar in Rufaydium so that we can get the url of the page that is active in Firefox, since different pages can have the same title, despite having different urls? 8-)
it's vice versa same title with a different URL and different URLs can have the same title, but we need to find out Handle of the active tab which was possible for chrome,
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
Sadaosh1970
Posts: 19
Joined: 29 Nov 2022, 06:52

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

26 Dec 2022, 08:41

For now, I'm using the script that I found in viewtopic.php?t=3702 and it works to discover the url of the active page in Firefox (if there aren't two different pages with the same url), then I pass control of that page to the Rufaydium.

Congratulations for your work. It's much simpler than using Selenium, even newbies like me can use it.

On the other hand, could you please confirm that the latest version of Rufaydium really cannot control Firefox? :think:

Thanks in advance.
User avatar
elModo7
Posts: 221
Joined: 01 Sep 2017, 02:38
Location: Spain
Contact:

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

28 Dec 2022, 03:27

Such an amazing lib, hadn't time to check it out yet but yeah, I've been using it a bit and it's deffinitely a big contribution! :bravo:
User avatar
Xeo786
Posts: 766
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

30 Dec 2022, 08:18

Sadaosh1970 wrote:
26 Dec 2022, 08:41
For now, I'm using the script that I found in viewtopic.php?t=3702 and it works to discover the url of the active page in Firefox (if there aren't two different pages with the same url), then I pass control of that page to the Rufaydium.

Congratulations for your work. It's much simpler than using Selenium, even newbies like me can use it.

On the other hand, could you please confirm that the latest version of Rufaydium really cannot control Firefox? :think:

Thanks in advance.
Yeah, but .activetab() bug persists, as you mentioned if someone opened multiple tabs with the same title it will activate the latest found tab, the simple and best way is to make records of all tabs now you know every tab, and which to access.
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
Sadaosh1970
Posts: 19
Joined: 29 Nov 2022, 06:52

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

30 Dec 2022, 09:18

Thank you.
.activetab() latest tab is good.

But the latest version of Rufaydium can no longer get into Firefox. :(

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 114 guests