stevepryde/thirtyfour

Persistent browser session

13hannes11 opened this issue · 6 comments

I want to create a tool that helps uses input data into a website. To avoid users having to login every time the script is started I would like to use a permanent browser session (like when using a webbrowser ordinarily).

I found this StackOverflow post which shows that this can be accomplished in Chrome by adding the argument user-data-dir=.

You can supply chrome options with the Capabilities struct. Have a look at the docs here:
https://docs.rs/thirtyfour/latest/thirtyfour/common/capabilities/chrome/struct.ChromeCapabilities.html

@stevepryde I am unfortunatly unable to add the option without getting an error message that it does not exist.

It works if I run chrome via the commandline via the following:

.\chrome.exe --user-data-dir=C:/Users/someuser/Repositories/Personal/autoconomy/chrome_profile

but I did not manage to translate this to the add_chrome_arg method.
I alwazs got the following error message: from invalid argument: unrecognized chrome option: and non of the following options worked:

caps.add_chrome_option("--user-data-dir=", "C:\\Users\\someuser\\chrome_profile")?;
caps.add_chrome_option("-user-data-dir=", "C:\\Users\\someuser\\chrome_profile")?;
caps.add_chrome_option("user-data-dir=", "C:\\Users\\someuser\\chrome_profile")?;

caps.add_chrome_option("--user-data-dir", "C:\\Users\\someuser\\chrome_profile")?;
caps.add_chrome_option("-user-data-dir", "C:\\Users\\someuser\\chrome_profile")?;
caps.add_chrome_option("user-data-dir", "C:\\Users\\someuser\\chrome_profile")?;

caps.add_chrome_option("--user-data-dir=C:\\Users\\someuser\\chrome_profile", "")?;
caps.add_chrome_option("-user-data-dir=C:\\Users\\someuser\\chrome_profile", "")?;
caps.add_chrome_option("user-data-dir=C:\\Users\\someuser\\chrome_profile", "")?;

I believe you need to use add_chrome_arg() not add_chrome_option().

I'll have a look at it a bit later.

Oh yeah that's right, I somehow exactly missed that. Thanks for the help.

The fix is to use add_chrome_arg like this:

 caps.add_chrome_arg("--user-data-dir=C:\\Users\\someuser\\chrome_profile")?;

Nice. Glad it's working!