Fix Chrome v124+ not closing on Windows. resolves #1161 (#1193)

This commit is contained in:
ilike2burnthing
2024-05-20 00:52:55 +01:00
committed by GitHub
parent c304da2964
commit 5a2c61601e
8 changed files with 15 additions and 15 deletions

View File

@@ -245,6 +245,7 @@ def _resolve_challenge(req: V1RequestBase, method: str) -> ChallengeResolutionT:
raise Exception('Error solving the challenge. ' + str(e).replace('\n', '\\n'))
finally:
if not req.session and driver is not None:
driver.close()
driver.quit()
logging.debug('A used instance of webdriver has been destroyed')

View File

@@ -66,6 +66,7 @@ class SessionsStorage:
return False
session = self.sessions.pop(session_id)
session.driver.close()
session.driver.quit()
return True

View File

@@ -788,15 +788,6 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
logger.debug("gracefully closed browser")
except Exception as e: # noqa
pass
# Force kill Chrome process in Windows
# https://github.com/FlareSolverr/FlareSolverr/issues/772
if os.name == 'nt':
try:
subprocess.call(['taskkill', '/f', '/pid', str(self.browser_pid)],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
except Exception:
pass
if (
hasattr(self, "keep_user_data_dir")
and hasattr(self, "user_data_dir")

View File

@@ -187,4 +187,5 @@ def test():
time.sleep(10)
driver.close()
driver.quit()

View File

@@ -314,6 +314,7 @@ def get_user_agent(driver=None) -> str:
raise Exception("Error getting browser User-Agent. " + str(e))
finally:
if driver is not None:
driver.close()
driver.quit()