Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium - share the browser session (cookies, local storage) between computers

I need to transfer my Selenium session between 2 computers.

To export and import the cookies via Selenium you have to visit each website individually before you can set its cookies, and I want to avoid that. I also want to copy over the local storage.

Here's what I've tried so far:

1 - Launch a fresh Selenium session:

driver = webdriver.Chrome()

2 - Find its temporary Chrome user profile in %temp% and copy it over to my application's folder

3 - Launch a new driver using this user profile:

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("user-data-dir=C:\\profiles\\temp_profile")
driver = webdriver.Chrome(chrome_options=chrome_options)

The above works - the local storage and the cookies are still there on my local PC, however, when I copy this user profile to another PC and launch it, then the local storage is still there, but the cookies are gone.

I have also tried the same using a regular chrome profile, as well as trying to launch the user profile directly in Chrome instead of Selenium, and the cookies are still gone.

like image 288
Bart Avatar asked Feb 24 '17 07:02

Bart


1 Answers

Since the cookies are stored in a SQLite file for Chrome, and they're encrypted, you don't really know (or want to dig in to..) why it doesn't work. It probably has something to do with information security.

So my suggestion would be to save them using WebDriver's functionality and load them in-memory. See here.

like image 180
Moshisho Avatar answered Sep 29 '22 09:09

Moshisho