Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post your working scripts, libraries and tools for AHK v1.1 and older
Flowgun
Posts: 74
Joined: 25 Aug 2022, 09:42

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Flowgun » 09 Dec 2022, 09:08

@Xeo786
Thank you a lot for the quick reply. I will try your suggestions =D

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

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Xeo786 » 09 Dec 2022, 09:38

automater wrote:
09 Dec 2022, 08:35
Hey @Xeo786, my code works perfectly except when I run headless mode. I've searched this thread and learned that it might have to do with cookies but I'm not sure how to load cookies.

I tried adding this below my capabilities but it didn't work:

Code: Select all

Cookies := Session.GetCookies()
I'm not surprised since that's just a variable assignment but I'm not sure what to do with the Cookies variable after the assignment.

How do I activate cookies when using headless mode?
Session.GetCookies() is used to retrieve cookies from a tab (that has finished loading a url) that is being accessed,
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

automater
Posts: 20
Joined: 01 Jul 2022, 08:51

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by automater » 09 Dec 2022, 10:32

@Xeo786 I'm not sure what I'm doing wrong but I can't get it to work.

Here is what my code looks like...I've tried both 'session.GetCookies()' and 'Page.GetCookies()' and both has not worked.

Code: Select all

#SingleInstance, Force
#include Rufaydium.ahk

Chrome := new Rufaydium("chromedriver.exe")
Chrome.capabilities.HeadlessMode := true
Chrome.capabilities.setUserProfile("Profile 2")
;Cookies := Session.GetCookies()
Page := Chrome.NewSession()
Page.Minimize()
Page.URL := "https://advertising.amazon.com/reports/new?entityId=ENTITY2LPDS70ON084I"
Page.GetCookies()

;ST REPORT
EnvAdd, CurrentDateTime, -60, day	;Subtracts 60 days from today's date
FormatTime, startDate, %CurrentDateTime%, LongDate	;Formats date to Tuesday, November 29, 2022
a := "[aria-label='Choose " startDate " as your start date.']"	;Concatenates string with startDate
FormatTime, endDate,, LongDate	;Formats date to Tuesday, November 29, 2022
b := "[aria-label='Choose " endDate " as your end date.']"	;Concatenates string with endDate

EnvAdd, CurrentDateTime, -14, day	;Subtracts 14 days from today's date
FormatTime, startDate, %CurrentDateTime%, LongDate	;Formats date to Tuesday, November 29, 2022
c := "[aria-label='Choose " startDate " as your start date.']"	;Concatenates string with startDate
FormatTime, endDate,, LongDate	;Formats date to Tuesday, November 29, 2022
d := "[aria-label='Choose " endDate " as your end date.']"	;Concatenates string with endDate

Page.querySelector(".sc-qPwPv.fXSQlL").click()	;Period dropdown

Page.querySelector(a).click()	;Clicks start date
Page.querySelector(b).click()	;Clicks end date
Page.querySelector(".sc-fznxsB.kRiLch").click()	;Save period
Sleep, 1000

Page.querySelector(".sc-storm-ui-30002725__sc-d3w8xm-1").Click()	;Run report
Sleep, 180000	;Wait for report to generate
Page.Refresh()	;Refresh page
Page.Refresh()	;Refresh page
Page.querySelector(".kCMTKY").Click()	;Clicks download button
Sleep, 10000

NewFileName := "Estrada Shoes US Search Term Report.xlsx"	;***********************
  Foo := "E:\Downloads"
  Loop %Foo%\*.*
   If ( A_LoopFileTimeModified >= Time )
     Time := A_LoopFileTimeModified, File := A_LoopFileLongPath
FileMove,%File%,C:\Users\jsrmt\OneDrive\PPC\Downloaded Reports\Search Term Reports\%NewFileName%, 1
Chrome.QuitAllSessions()
Any help is appreciated. Thanks!

Flowgun
Posts: 74
Joined: 25 Aug 2022, 09:42

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Flowgun » 09 Dec 2022, 11:29

@Xeo786
I'm trying to find solutions for how to use chrome profiles. I like using the default profile for example. I don't mind closing my chrome and opening it with Rufaydium when I need automation (or automating the closing/re-opening), but Rufaydium seems to open only one Chrome window if I happen to use multiple chrome windows on the same profile. I find this behavior risky and I already lost many old tabs in other windows that I was doing some research with. Is there a solution for this?

Dec
Posts: 2
Joined: 09 Dec 2022, 07:17

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Dec » 09 Dec 2022, 14:30

Xeo786 wrote:
09 Dec 2022, 08:10
Dec wrote:
09 Dec 2022, 07:34
Hello,

Sorry if this is a bit off-topic but I'm a complete newbie to AHK and to programming in general.

I just wanted to ask if it's possible to retrieve certain fields from a webpage for later use. For more background information, I'm trying to write out a script that will store the information from a couple of fields from one of the webpages I'm currently viewing and I was wondering if Rufaydium would do the trick, I'm also wondering if it needs a new session each time the script is being run or if it can either run in the background to retrieve those values or use the same browser instance after it's been started via the .AHK file. I'm basically using this to automatically unzip some archives that were just downloaded, create new folders according to those two fields, scan the folder containing the newly created folders and have a drop-down menu automatically start up Notepad++ Workspaces depending on my drop-down menu choice (everything else is basically out of scope but I just wanted to offer a bit of insight into what I'm trying to do). Thanks in advance :)
Your task seems simple you can use winhttp request, Winhttp will work in background no browser is needed.
look into this URLDownloadtoFile,Webscraping, WinHTTPrequests and more
Thank you very much for the answer! I've been trying to look into WinHTTP and I'm not sure if it's going to work to be honest. I've been looking into it with Fiddler just to see exactly what is happening when I'm accessing the website, as far as I can see the data that I need is stored in one of the JSONs (the HTLM doesn't contain any of the information I actually want) and as far as I can see there's basically going to be a different one each time.

I can't seem to find anything that would link two different pages between them (at the moment I'm basically trying to make work a bit more easier by downloading log bundles from our ticketing tool and then just launching them up in Notepad++ directly just to keep everything tidy and organized). I'm also aware that there's multiple different ways to actually do this but I've been having fun even though I haven't made any real progress on this part of the project.

Honestly, I feel like relying on a browser wouldn't be that much of a deal-breaker for me if I would be able to use the same browser window for the entire day (i.e. not having to open one each time I download the logs). Also, if something doesn't seem like it makes sense about my explanation, then it most likely doesn't (I somehow got to this point by Googling so I guess I'll keep chugging along). Just let me know if I'm being dumb and I will go back to trying WinHTTP. Thank you very much for your help so far :)

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

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Xeo786 » 10 Dec 2022, 00:25

I saw you are not saving that cookie object, Session.GetCookies() returns an object containing cookies, you can look into an object by doing JSON dump

Code: Select all

Cookies := Session.GetCookies() ; you have store the result 
msgbox, % json.Dump(Cookies,1) 
automater wrote:
09 Dec 2022, 10:32
I've tried both 'session.GetCookies()' and 'Page.GetCookies()' and both has not worked.
Session is just a variable (anything can be variable) unless something is stored into it. NewSession() is a method that returns with Session Class object, so we store it into some variable to access it in your case its a page variable, Please learn AutoHotkey basics's like Variables and Objects it will help you a lot.
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

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

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Xeo786 » 10 Dec 2022, 00:31

Flowgun wrote:
09 Dec 2022, 11:29
@Xeo786
I'm trying to find solutions for how to use chrome profiles. I like using the default profile for example. I don't mind closing my chrome and opening it with Rufaydium when I need automation (or automating the closing/re-opening), but Rufaydium seems to open only one Chrome window if I happen to use multiple chrome windows on the same profile. I find this behavior risky and I already lost many old tabs in other windows that I was doing some research with. Is there a solution for this?
Have you read Rufaydium Docs and examples? define Capabilities to load session to with desire options.
It is all there, and with Session.NewWindow() you can open multiple windows within one session.
Last edited by Xeo786 on 10 Dec 2022, 07:24, edited 1 time in total.
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

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

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Xeo786 » 10 Dec 2022, 01:10

Dec wrote:
09 Dec 2022, 14:30
Honestly, I feel like relying on a browser wouldn't be that much of a deal-breaker for me if I would be able to use the same browser window for the entire day (i.e. not having to open one each time I download the logs). Also, if something doesn't seem like it makes sense about my explanation, then it most likely doesn't (I somehow got to this point by Googling so I guess I'll keep chugging along). Just let me know if I'm being dumb and I will go back to trying WinHTTP. Thank you very much for your help so far :)
If you learn at least one thing in a day, you are on the right track. You can try Rufaydium but it is better user knows the basics of AHK, JS, HTML, and Devtools. HTML and JS are also involved with JSON and HTTP. Rufaydium is so easy that a noob with no basic knowledge can create a session and automate chrome by reading the documentation but he will waste so much time being confused while achieving the desired goal unless he made up his mind to learn how things work? how they are built?
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

Flowgun
Posts: 74
Joined: 25 Aug 2022, 09:42

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Flowgun » 12 Dec 2022, 11:18

Hello again,

I'm having a problem creating multiple sessions when I use capabilities to set up the user profile.
When I don't set any capability, Page := chrome.NewSession() keeps on creating new sessions without any problem (but not with the user profile that I want).

If I specify a user profile with capabilities, and I have chrome open (be it with web driver or not, in any user profile), creating a new session opens the new session, but yells at me with an error :

unknown error: Chrome failed to start: exited normally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location <location>
is no longer running, so ChromeDriver is assuming that Chrome has
crashed.)

I tried opening multiple sessions with a specified UserProfile with different ways, but all of them failed. I tried different chromedriver.exe in different locations and different ports, naming the pages and the "new Rufaydium" object differently, trying to open the same userProfile or different ones...

it seems that the only way to open a new session with the user profile that I want is to close all chrome sessions, no matter if they are open with Rufaydium/Web Driver, or manually, no matter if it's the currently-open user profile or not. But for some reason, opening with no specified user Profile works without an error.

Am I missing something here? is there a way to stop that error from showing ("try" doesn't do it as it's not thrown by ahk).

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

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Xeo786 » 13 Dec 2022, 00:03

Flowgun wrote:
12 Dec 2022, 11:18
Hello again,

I'm having a problem creating multiple sessions when I use capabilities to set up the user profile.
When I don't set any capability, Page := chrome.NewSession() keeps on creating new sessions without any problem (but not with the user profile that I want).

If I specify a user profile with capabilities, and I have chrome open (be it with web driver or not, in any user profile), creating a new session opens the new session, but yells at me with an error :

unknown error: Chrome failed to start: exited normally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location <location>
is no longer running, so ChromeDriver is assuming that Chrome has
crashed.)

I tried opening multiple sessions with a specified UserProfile with different ways, but all of them failed. I tried different chromedriver.exe in different locations and different ports, naming the pages and the "new Rufaydium" object differently, trying to open the same userProfile or different ones...

it seems that the only way to open a new session with the user profile that I want is to close all chrome sessions, no matter if they are open with Rufaydium/Web Driver, or manually, no matter if it's the currently-open user profile or not. But for some reason, opening with no specified user Profile works without an error.

Am I missing something here? is there a way to stop that error from showing ("try" doesn't do it as it's not thrown by ahk).
Rufaydium uses Webdriver, it Webdriver poilicy you cannot create multiple session using one profile, because you can create multiple Windows within one session.

Session.NewWindow()
"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)

Post by Sadaosh1970 » 13 Dec 2022, 11:42

Please, I have a question.
If I have multiple tabs open (tab 1,1, tab 1,2, 1,3, 1,4...).
How do I determine the position of the active tab in Firefox, to use the following command?

Code: Select all

Page := Firefox.getSession(1,n) ; n = number of active tab in Firefox
Tank You!

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

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Xeo786 » 14 Dec 2022, 00:36

Sadaosh1970 wrote:
13 Dec 2022, 11:42
Please, I have a question.
If I have multiple tabs open (tab 1,1, tab 1,2, 1,3, 1,4...).
How do I determine the position of the active tab in Firefox, to use the following command?

Code: Select all

Page := Firefox.getSession(1,n) ; n = number of active tab in Firefox
Tank You!
its already defined here, its getSession(Number_of_Session, Number_of_Tab_from_Left2Right)
"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)

Post by Sadaosh1970 » 14 Dec 2022, 07:19

Dear Xeo786!
Thanks for answering!
I apologize, but I don't speak English. So, I couldn't correctly formulate my question earlier. I'll try again, sorry if it's too long. :headwall:

I know that I have to pass control of each open tab in Firefox to Rudaydium using:
Page := Firefox.getSession(1,n) ; n = number of the tab that will be controlled.

But sometimes I have to control a tab that was opened manually or when I clicked with the mouse, but I have no way of knowing that tab's number automatically.

To pass control of this tab to Rufaydium I am using the following trick:

Code: Select all

send, {f6} ; firefox shortcut for url bar
send, ^c ; capture the url on the tab I want to control
url_active = %clipboard%
Page := FF.getSessionByUrl(url_active) ; now rufaydium controls the new tab
This trick works fine on my home computer. But it doesn't work on the office computer, I think by admin settings, I don't know.

But the office computer accepts:

Code: Select all

Page := Firefox.getSession(1,x)
My question is how to automatically determine the number of the tab that is active in Firefox, but is not yet being controlled by Rufaydium.

Suppose Rufaydium is controlling tab(1,2), but I am browsing in Firefox on tab tab(1,X).

Is there any way to automatically capture the number X and pass it to Rufaydium (Page := Firefox.getSession(1,X).

Thank you and sorry for the long text!

Flowgun
Posts: 74
Joined: 25 Aug 2022, 09:42

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Flowgun » 14 Dec 2022, 19:52

Hello, @Xeo786

I was able to write a code that allows opening multiple Chrome profiles that still work with Rufaydium, and it works around errors that I was commonly getting. It is probably not optimal, but it works:

Code: Select all

OpenChrome:
{
Chrome := new Rufaydium(A_ScriptDir "\_ScriptData\Libraries\chromedriver.exe")	;;; opens the chrome driver, or joins it if it exists
if (ChromeProfile="")
	ChromeProfile:= "Default"
Chrome.capabilities.setUserProfile(ChromeProfile)
Chrome.capabilities.addArg(" --force-launch-browser --hide-crash-restore-bubble --restore-last-session")

if winexist("ahk_exe chrome.exe")
	{
		 if (json.dump(Chrome.sessions())= "[]") ;;; if chrome is open but not hooked to the driver
			{
			RestartingChrome(A_ThisFunc, 1)
			gosub, WaitForApolloPage
			}
		else
			try 
				{
				page:= chrome.getsession(1)	;;; if the chrome is open but hooked wrongly to the driver (?)
				run, % "chrome.exe --profile-directory=" """" ChromeProfile """" " --force-launch-browser --hide-crash-restore-bubble --restore-last-session"
				page:= chrome.getsession(1)
				}
			catch
				{
				RestartingChrome(A_ThisFunc)
				}
	}
else
	Page := Chrome.NewSession()

return
}
I haven't cleaned "RestartingChrome" function to share it, but it's basically a simple message box that pops up when Chrome needs to be closed to open it with Rufaydium. It closes the Chrome Driver and the chrome process, crashing it, which allows to restart all of the windows with these arguments: Chrome.capabilities.addArg("--force-launch-browser --hide-crash-restore-bubble --restore-last-session")

Code: Select all

	MsgBox,4406, Close Chrome, All instances of Chrome need to be closed so that it can be relaunched in Automation mode.`nPress "Cancel" to abort, "Try Again" to recheck if it was closed manually, or "Continue" to close all instances, and relaunch this profile (keeping all the windows and tabs).
	IfMsgBox, Cancel
Since I usually want to restart the latest Chrome profile in use, the solution I found is to refresh the page with common chrome functions and hotkeys, which changes the date of the corresponding User Profile folder, and then I parse the profile folders by date. I also copy the address bar with common functions so that then I can locate its window with "GetSessionByUrl" once chrome is relaunched in Rufaydium mode:

Code: Select all

			winactivate,  ahk_exe chrome.exe
			ClipSaver:=ClipboardAll
					Clipboard:=""
					send, {Ctrl down}l{ctrl up}		;;; to highlight address bar, equivalent to {F6} or Alt+d (but better for ahk)
					send, {Ctrl down}c{ctrl up}
					clipwait, 1
					if (ErrorLevel=0)
						CurrentTab:=Clipboard
					Clipboard:=Clipsaver
			
			send, {F5}	; to refresh a page so that the most recent folder updates to the current profile
			ChromeProfileDir:= StrReplace(A_AppData, "\Roaming") "\Local\Google\Chrome\User Data"
			LastUsedProfile:="Default"
			FileGetTime, %LastUsedProfile%, %ChromeProfileDir%\Default, M

			loop, Files, %ChromeProfileDir%\Profile*, D
				{
					FileGetTime, X, %ChromeProfileDir%\%A_LoopFileName%, M
					If ( X > %LastUsedProfile%)
						LastUsedProfile:= A_LoopFileName
				}
Maybe I should specify that I also built a Gui that parses the profile folders and adds them as a dropdown list so that I can open the wanted Chrome Profile with it using the g-label I shared.
I'm pretty sure there are better ways to do all of the above. I didn't want to modify the original library, and this is what I came up with. While writing the code, I didn't find a way to retrieve what Chrome Profiles are currently open/active (either if they are hooked to the driver or not). "Session()" doesn't provide that info. If there's a way to get that info (without opening extra tabs that have the info to retrieve it), that would be helpful.
Sorry if I was annoying and asking too many noob questions. I appreciate your attitude. Peace.

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

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Xeo786 » 15 Dec 2022, 01:24

Flowgun wrote:
14 Dec 2022, 19:52
Hello, @Xeo786

I was able to write a code that allows opening multiple Chrome profiles that still work with Rufaydium, and it works around errors that I was commonly getting. It is probably not optimal, but it works:

Code: Select all

OpenChrome:
{
Chrome := new Rufaydium(A_ScriptDir "\_ScriptData\Libraries\chromedriver.exe")	;;; opens the chrome driver, or joins it if it exists
if (ChromeProfile="")
	ChromeProfile:= "Default"
Chrome.capabilities.setUserProfile(ChromeProfile)
Chrome.capabilities.addArg(" --force-launch-browser --hide-crash-restore-bubble --restore-last-session")

if winexist("ahk_exe chrome.exe")
	{
		 if (json.dump(Chrome.sessions())= "[]") ;;; if chrome is open but not hooked to the driver
			{
			RestartingChrome(A_ThisFunc, 1)
			gosub, WaitForApolloPage
			}
		else
			try 
				{
				page:= chrome.getsession(1)	;;; if the chrome is open but hooked wrongly to the driver (?)
				run, % "chrome.exe --profile-directory=" """" ChromeProfile """" " --force-launch-browser --hide-crash-restore-bubble --restore-last-session"
				page:= chrome.getsession(1)
				}
			catch
				{
				RestartingChrome(A_ThisFunc)
				}
	}
else
	Page := Chrome.NewSession()

return
}
I haven't cleaned "RestartingChrome" function to share it, but it's basically a simple message box that pops up when Chrome needs to be closed to open it with Rufaydium. It closes the Chrome Driver and the chrome process, crashing it, which allows to restart all of the windows with these arguments: Chrome.capabilities.addArg("--force-launch-browser --hide-crash-restore-bubble --restore-last-session")

Code: Select all

	MsgBox,4406, Close Chrome, All instances of Chrome need to be closed so that it can be relaunched in Automation mode.`nPress "Cancel" to abort, "Try Again" to recheck if it was closed manually, or "Continue" to close all instances, and relaunch this profile (keeping all the windows and tabs).
	IfMsgBox, Cancel
Since I usually want to restart the latest Chrome profile in use, the solution I found is to refresh the page with common chrome functions and hotkeys, which changes the date of the corresponding User Profile folder, and then I parse the profile folders by date. I also copy the address bar with common functions so that then I can locate its window with "GetSessionByUrl" once chrome is relaunched in Rufaydium mode:

Code: Select all

			winactivate,  ahk_exe chrome.exe
			ClipSaver:=ClipboardAll
					Clipboard:=""
					send, {Ctrl down}l{ctrl up}		;;; to highlight address bar, equivalent to {F6} or Alt+d (but better for ahk)
					send, {Ctrl down}c{ctrl up}
					clipwait, 1
					if (ErrorLevel=0)
						CurrentTab:=Clipboard
					Clipboard:=Clipsaver
			
			send, {F5}	; to refresh a page so that the most recent folder updates to the current profile
			ChromeProfileDir:= StrReplace(A_AppData, "\Roaming") "\Local\Google\Chrome\User Data"
			LastUsedProfile:="Default"
			FileGetTime, %LastUsedProfile%, %ChromeProfileDir%\Default, M

			loop, Files, %ChromeProfileDir%\Profile*, D
				{
					FileGetTime, X, %ChromeProfileDir%\%A_LoopFileName%, M
					If ( X > %LastUsedProfile%)
						LastUsedProfile:= A_LoopFileName
				}
Maybe I should specify that I also built a Gui that parses the profile folders and adds them as a dropdown list so that I can open the wanted Chrome Profile with it using the g-label I shared.
I'm pretty sure there are better ways to do all of the above. I didn't want to modify the original library, and this is what I came up with. While writing the code, I didn't find a way to retrieve what Chrome Profiles are currently open/active (either if they are hooked to the driver or not). "Session()" doesn't provide that info. If there's a way to get that info (without opening extra tabs that have the info to retrieve it), that would be helpful.
Sorry if I was annoying and asking too many noob questions. I appreciate your attitude. Peace.
Command lines switch that you are passing, are telling what is going on, you are restoring the last session and hiding the crash bubble, and that is restored, but the question is why its crashes?
You have to understand a few points,
  • Browser profile which is being accessed by Browser Session, will fail to load for web driver Session
  • Same goes for two Webdriver sessions accessing the same profile
  • You cannot load multiple profiles into one session, If You want to load another profile Create another session
  • there is no point in creating a session with the same profile because you can just create New Window which will be having the same profile
here is some way to access the same profile under multiple chrome windows.

Make sure no chrome running because it will be running using the Default profile.

Code: Select all

Chrome := new Rufaydium()
Chrome.capabilities.setUserProfile("Default") 
i := 0
Page := Chrome.NewSession()
Page.Url := "Some.Url.num_" ++i
msgbox, Press F1 to create a sessoin.
return
f1::
Page.NewWindow()
Page.Url := "Some.Url.num_" ++i
msgbox, % "You create a New Window with url " Page.url
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

Flowgun
Posts: 74
Joined: 25 Aug 2022, 09:42

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Flowgun » 15 Dec 2022, 08:26

@Xeo786
I intentionally crash Chrome by using " Process, Close, chrome.exe ". this way, re-opening it gives the option to restore all the windows.
If I simply close it, it will only restore the latest closed Window.

I often work with multiple windows within the same profile, and I'm working on a software that the client wants to be able to use with multiple Chrome Profiles. The reason is that they have different Bookmarks in their different Chrome profiles that they use in their workflow, and I want to make it smooth for them to open any of these profiles and work with them, and still have the ability to scrape the active window, no matter what the Profile is.

I noticed that when I open a new profile with the code I wrote, I can simply use a code like this:

Code: Select all

winactivate, ahk_exe chrome.exe
ClipSaver:=ClipboardAll
Clipboard:=""
send, {Ctrl down}l{ctrl up}		;;; to highlight address bar, equivalent to {F6} or Alt+d (but better for ahk to avoid alt being stuck)
send, {Ctrl down}c{ctrl up}
clipwait, 1
CurrentTab:=Clipboard
Clipboard:=Clipsaver

Page:= Chrome.GetSessionByUrl(CurrentTab)
This will make Rufaydium get that session and start working with it, no matter what Profile session was initially started with it.
I tried getting the session by active tab and so on, but that would make Rufaydium only get the initial profile session (and sometimes it gets the wrong address, maybe depending on lag in WebDriver.exe). I don't know why, but GetSessionByURL just works across profiles.

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

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Xeo786 » 16 Dec 2022, 01:43

Flowgun wrote:
15 Dec 2022, 08:26
@Xeo786
I intentionally crash Chrome by using " Process, Close, chrome.exe ". this way, re-opening it gives the option to restore all the windows.
If I simply close it, it will only restore the latest closed Window.

I often work with multiple windows within the same profile, and I'm working on a software that the client wants to be able to use with multiple Chrome Profiles. The reason is that they have different Bookmarks in their different Chrome profiles that they use in their workflow, and I want to make it smooth for them to open any of these profiles and work with them, and still have the ability to scrape the active window, no matter what the Profile is.

I noticed that when I open a new profile with the code I wrote, I can simply use a code like this:

Code: Select all

winactivate, ahk_exe chrome.exe
ClipSaver:=ClipboardAll
Clipboard:=""
send, {Ctrl down}l{ctrl up}		;;; to highlight address bar, equivalent to {F6} or Alt+d (but better for ahk to avoid alt being stuck)
send, {Ctrl down}c{ctrl up}
clipwait, 1
CurrentTab:=Clipboard
Clipboard:=Clipsaver

Page:= Chrome.GetSessionByUrl(CurrentTab)
This will make Rufaydium get that session and start working with it, no matter what Profile session was initially started with it.
I tried getting the session by active tab and so on, but that would make Rufaydium only get the initial profile session (and sometimes it gets the wrong address, maybe depending on lag in WebDriver.exe). I don't know why, but GetSessionByURL just works across profiles.
This way you can load multiple session

Code: Select all

Chrome := new Rufaydium()
Chrome.capabilities.setUserProfile("Default") 
Page1 := Chrome.NewSession()  
msgbox, created session with "Default" profile
Chrome.capabilities.setUserProfile("Profile 1") 
Page2 := Chrome.NewSession()  
msgbox, created session with "Profile 1"profile
Chrome.capabilities.setUserProfile("Profile 2") 
Page3 := Chrome.NewSession()  
msgbox, created session with "Profile 2"profile
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

Flowgun
Posts: 74
Joined: 25 Aug 2022, 09:42

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Flowgun » 16 Dec 2022, 05:38

This way you can load multiple session

Code: Select all

Chrome := new Rufaydium()
Chrome.capabilities.setUserProfile("Default") 
Page1 := Chrome.NewSession()  
msgbox, created session with "Default" profile
Chrome.capabilities.setUserProfile("Profile 1") 
Page2 := Chrome.NewSession()  
msgbox, created session with "Profile 1"profile
Chrome.capabilities.setUserProfile("Profile 2") 
Page3 := Chrome.NewSession()  
msgbox, created session with "Profile 2"profile
This opens the profile, but it shows me the messagebox with this error I was talking about. I don't know why it thinks that chrome is closed, although it's open and running:

Rufaydium WebDriver Support Error
unknown error
unknown error: Chrome failed to start: exited normally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location Files
is no longer
running, so ChromeDriver is assuming that Chrome has
crashed.)

Is this error not reproducible? for me, it shows every time with the code you shared.

That's why, if Chrome is already open with Web Driver, I open the new profile session using the normal "Run" command (with the argument of the corresponding profile). I found out that even then, the newly-opened sessions can be hooked with the web driver via "Chrome.getSessionByUrl".
Last edited by Flowgun on 16 Dec 2022, 13:24, edited 1 time in total.

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

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Xeo786 » 16 Dec 2022, 06:07

Flowgun wrote:
16 Dec 2022, 05:38
This way you can load multiple session

Code: Select all

Chrome := new Rufaydium()
Chrome.capabilities.setUserProfile("Default") 
Page1 := Chrome.NewSession()  
msgbox, created session with "Default" profile
Chrome.capabilities.setUserProfile("Profile 1") 
Page2 := Chrome.NewSession()  
msgbox, created session with "Profile 1"profile
Chrome.capabilities.setUserProfile("Profile 2") 
Page3 := Chrome.NewSession()  
msgbox, created session with "Profile 2"profile
This opens the profile, but it shows me the messagebox with this error I was talking about. I don't why it thinks that chrome is closed, although it's open and running:

Rufaydium WebDriver Support Error
unknown error
unknown error: Chrome failed to start: exited normally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location Files
is no longer
running, so ChromeDriver is assuming that Chrome has
crashed.)

Is this error not reproducible? for me, it shows every time with the code you shared.

That's why, if Chrome is already open with Web Driver, I open the new profile session using the normal "Run" command (with the argument of the corresponding profile). I found out that even then, the newly-opened sessions can be hooked with the web driver via "Chrome.getSessionByUrl".
What I found out now, Well one cannot use the same user data dir , I just tested, run two session on same driver with different profile, and User data dir
image.png
image.png (7.11 KiB) Viewed 2906 times
You need to maintain user data dir somewhere else, here is the example

Code: Select all

UserDATADir1 := A_ScriptDir "\DIR 1"
Profile1 := UserDATADir1 "\Profile1"
UserDATADir2 := A_ScriptDir "\DIR 2"
Profile2 := UserDATADir2 "\Profile2"

; creating dir in case they do not exist
if !FileExist(UserDATADir1)
    FileCreateDir, % UserDATADir1
if !FileExist(UserDATADir2)
    FileCreateDir, % UserDATADir2
if !FileExist(Profile1)
    FileCreateDir, % Profile1
if !FileExist(Profile2)
    FileCreateDir, % Profile2    

Chrome := new Rufaydium()
Chrome.capabilities.setUserProfile("Profile1",UserDATADir1)  ; make sure you pass Profile1 "folderName" not the whole address
Page1 := Chrome.NewSession()  
Chrome.capabilities.setUserProfile("Profile2",UserDATADir2) 
Page2 := Chrome.NewSession()  
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

Flowgun
Posts: 74
Joined: 25 Aug 2022, 09:42

Re: Rufaydium WebDriver 1.7.2 (no selenium/websocket)

Post by Flowgun » 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.

Post Reply

Return to “Scripts and Functions (v1)”