1

I am trying to run a Chrome webdriver with extension and it is working on non remote setup, but as soon as I set up remote webdriver, it fails to start. Here is what system outputs:

selenium.common.exceptions.SessionNotCreatedException: Message: Could not start a new 
session. Error while creating session with the driver service. Stopping driver 
service: Could not start a new session. Response code 500. Message: unknown error: 
failed to wait for extension background page to load: chrome- 
extension://bfnaelmomeimhlpmgjnjophhpkkoljpa/_generated_background_page.html
from unknown error: page could not be found: chrome- 
extension://bfnaelmomeimhlpmgjnjophhpkkoljpa/_generated_background_page.html
Build info: version: '4.1.1', revision: 'e8fcc2cecf'
System info: host: 'ec5758b8a125', ip: '172.17.0.2', os.name: 'Linux', os.arch: 
'amd64', os.version: '5.10.25-linuxkit', java.version: '11.0.13'
Driver info: driver.version: unknown
Build info: version: '4.1.1', revision: 'e8fcc2cecf'
System info: host: 'ec5758b8a125', ip: '172.17.0.2', os.name: 'Linux', os.arch: 
  'amd64', os.version: '5.10.25-linuxkit', java.version: '11.0.13'
Driver info: driver.version: unknown

Here is my driver.py file:

def initialize():
   global instance
   options = webdriver.ChromeOptions()
   prefs = {'download.default_directory': '/driver/extensions'}
   options.add_experimental_option('prefs', prefs)
   options.add_extention('path/to/extension')
   options.add_argument('--headless') 
   instance = 
   webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.CHROME, 
   options=options) 
   # instance = webdriver.Chrome(options=options) # this is working 
   instance.implicitly_wait(2) 
   return instance
   
DZR
  • 195
  • 1
  • 2
  • 12
  • `instance = webdriver.Chrome(options=options)`: this is working or not working? – undetected Selenium Jan 24 '22 at 12:00
  • hi @undetectedSelenium. that is working since its not remote. the one above is not working. webdriver.Remote :(. I don't know why and trying to figure out for a while. – DZR Jan 24 '22 at 12:02
  • Does it work on local env in headless mode? Since headless mode doesn't support extensions. Try to remove the headless option on the remote. – Max Daroshchanka Jan 24 '22 at 13:20
  • @DZR thanks for the response. I'll leave the answer for the community. – Max Daroshchanka Jan 25 '22 at 14:17
  • thanks again. I have another one :) https://stackoverflow.com/questions/70850423/give-remote-driver-capability-to-download-a-file-to-specified-location in case you know :D – DZR Jan 25 '22 at 14:29

1 Answers1

1

To make Chrome webdriver be able to run with an extension it should be non-headless.

This config should be removed:

options.add_argument('--headless') 

Reference

https://bugs.chromium.org/p/chromium/issues/detail?id=706008

Max Daroshchanka
  • 2,698
  • 2
  • 10
  • 14