OS: Ubuntu 20.04 no GUI.
I'm doing a quite simple task there in headless mode:
- Installing and enabling firefox addon.
- Navigating to about:debugging#/runtime/this-firefox and getting addon's uuid.
The problem is that after a few successful .py script completions, next ones just hang and return Connection refused (os error 111) error. After that I have to reboot the server which fix issue for a few .py script launches only.
My code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver import FirefoxProfile
import time
ff_options = FirefoxOptions()
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ff/85.0.4183.83 Safari/537.36"
ff_options.add_argument('-headless')
ff_options.add_argument(f'user-agent={user_agent}')
ff_options.add_argument('--disable-dev-shm-usage')
ff_options.add_argument('--no-sandbox')
ff_options.add_argument("--window-size=1920,1080")
ff_options.add_argument('--ignore-certificate-errors')
ff_options.add_argument('--allow-running-insecure-content')
ff_options.add_argument("--proxy-server='direct://'")
ff_options.add_argument("--proxy-bypass-list=*")
ff_options.add_argument("--start-maximized")
ff_options.add_argument('--disable-gpu')
ff_options.add_argument('--disable-setuid-sandbox')
buster = "/root/my_simple_extension.xpi"
driver = webdriver.Firefox(executable_path='/usr/local/share/geckodriver', options=ff_options)
driver.install_addon(buster, temporary=True)
driver.profile = webdriver.FirefoxProfile()
driver.profile.add_extension(buster)
driver.profile.set_preference("security.fileuri.strict_origin_policy", False)
driver.profile.update_preferences()
driver.get("about:debugging#/runtime/this-firefox")
time.sleep(1)
parent1 = driver.find_element_by_xpath('(//div[@class="fieldpair"])[position()=3]')
uuid = parent1.text.splitlines()[1]
driver.get('moz-extension://{}/home.html'.format(uuid))
time.sleep(1)
print(driver.page_source)
driver.quit()
geckodriver.log
1632303683203 geckodriver INFO Listening on 127.0.0.1:45055
1632303684204 mozrunner::runner INFO Running command: "/usr/bin/firefox" "--marionette" "-headless" "user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ff/85.0.4183.83 Safari/537.36" "--disable-dev-shm-usage" "--no-sandbox" "--window-size=1920,1080" "--ignore-certificate-errors" "--allow-running-insecure-content" "--proxy-server=\'direct://\'" "--proxy-bypass-list=*" "--start-maximized" "--disable-gpu" "--disable-setuid-sandbox" "-no-remote" "-profile" "/tmp/rust_mozprofilexOejpk"
*** You are running in headless mode.
[GFX1-]: glxtest: Unable to open a connection to the X server
[GFX1-]: glxtest: libEGL missing
1632303684813 Marionette INFO Marionette enabled
[GFX1-]: RenderCompositorSWGL failed mapping default framebuffer, no dt
console.warn: SearchSettings: "get: No settings file exists, new profile?" (new NotFoundError("Could not open the file at /tmp/rust_mozprofilexOejpk/search.json.mozlz4", (void 0)))
1632303687471 Marionette INFO Listening on port 42933
1632303687541 RemoteAgent WARN TLS certificate errors will be ignored for this session
JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/background-8.js, line 17: asm.js type error: expecting argument type declaration for 'e' of the form 'arg = arg|0' or 'arg = arg' or 'arg = fround(arg)'
JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
JavaScript warning: moz-extension://c135a3be-0987-411e-b62f-413239ad2d16/ui-3.js, line 7: unreachable code after return statement
1632303696737 Marionette INFO Stopped listening on port 42933
Port.onMessage event fired while context is inactive.
Port.onMessage event fired while context is inactive.
Port.onMessage event fired while context is inactive.
JavaScript error: resource:///modules/Interactions.jsm, line 230: NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIUserIdleService.removeIdleObserver]
CodePudding user response:
Having just the source code of the test doesn't really help to give a qualified answer for your issue. As such please create trace logs while the test is running and share these with us. The additional information as logged to a file (should be geckodriver.log in your case) can help to understand the situation, and finally to propose a solution. Thanks.
CodePudding user response:
Thank you furas for getting me on the track. It appears that after some python code error, driver.quit() wasn't executed which lead to multiple hanging firefox processes. Quitting them with sudo pkill -9 firefox solved the issue.