title: Installing extensions into Selenium Grid (remote driver) under local Python 3 to a remote server running under docker
body: <p>I have changed the title of this post to make it easier to find, and have solved the issue. See my answer below.</p>
  <p>OLD TITLE -  Selenium Grid 4.0.0.Beta-1 Docker driver crashes my python app when adding chrome extensions when Selenium local does not</p>
  <p>I have hunted high and low for a recent answer and tried most of the older ones (so please do not mark this is as duplicate) and every site that google presented me ..nothing works so far. I want to use the latest version of Selenium Grid (Docker image) , I have it set up and working, and I can scrape data remotely as long as I do not have an extension installed or define a user directory, as follows...</p>
  <p>This code does work, but it runs on a local browser and not on the docker Selenium Grid.</p>
  <pre><code>from selenium import webdriver
  from selenium.webdriver import Chrome
  from selenium.webdriver.chrome.options import Options
  from selenium.webdriver.support.ui import WebDriverWait
  from selenium.webdriver.support import expected_conditions as ec
  from selenium.webdriver.common.by import By
  from selenium.common.exceptions import TimeoutException
  from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
  
  class sgrid:    
         
      def init_chrome_with_cookies_local(self):
          chrome_options = Options()
          chrome_options.add_extension(r'C:\Users\charl\OneDrive\python\vidiqext\3.41.0_0.crx')
          chrome_options.add_argument(&quot;user-data-dir=C:/Users/charl/OneDrive/python/userdata&quot;) 
          driver = webdriver.Chrome(options=chrome_options) 
          return driver
      
  </code></pre>
  <p>But when I switch to this</p>
  <pre><code>    def init_chrome_with_cookies_remote(self):
          chrome_options = Options()
          chrome_options.add_extension(r'C:\Users\charl\OneDrive\python\vidiqext\3.41.0_0.crx')
          chrome_options.add_argument(r'user-data-dir=C:/Users/charl/OneDrive/python/userdata')
          driver = webdriver.Remote(command_executor='http://x.x.x.x:4444/wd/hub',options=chrome_options)
          return driver
  </code></pre>
  <p>....it crashes, and it does not matter if both the add_extension and add_argument are tried, or one then the other, they both cause the app to crash.</p>
  <p>File &quot;c:/Users/charl/OneDrive/python/sgrid.py&quot;, line 183, in iterate
  driver.get('about:blank')
  UnboundLocalError: local variable 'driver' referenced before assignment
  PS C:\Users\charl\OneDrive\dataharvest\visualstudio&gt;</p>
  <p>This error really just means the driver did not get configured properly as all the other code is the same.  Now I understand that some solutions on StackOverflow  use the DesiredCapabilities way, but I am told that this is deprecated, and none have worked either so if anyone has this working in Python 3, Selenium Grid 4 on docker, I would be so grateful to know.</p>
  <p>EDIT: It might be worth noting that my local machine is Windows Anaconda and my Remote machine is Debian running Docker, they are not on the same machine. Do I need to stipulate the paths to these files/directories on the local or remote machines?</p>
  <p>EDIT 2: The path to either the crx file or the user-data-dir should be local to the remote machine, I have worked out, which is /dev/shm in my case which must be available both inside and outside the docker container, and not the local machine. It still crashes but after adding user data remotely, so part of the solution is now found. This is not obvious as the command driver.save_screenshot(...) for instance saves files locally.</p>
  <p>Under this scenario</p>
  <pre><code>chrome_options.add_argument(&quot;user-data-dir=/dev/shm/vidiq&quot;)
  </code></pre>
  <p>seems to work (files are created by chrome normally, and it does not crash, and scrapes blank data because there is no VidIQ extension), but ...</p>
  <pre><code>chrome_options.add_extension('/dev/shm/3.41.0_0.crx')
  </code></pre>
  <p>crashes the driver immediately. I checked remote permissions, 777 and 666 respectively.</p>
  <p>Edit 3: Can confirm that the crx file and user data should have a remote path, But still no joy in spinning up a remote Selenium Grid with an extension.</p>