Fix occasional headless issue on Linux when set to "false" (#1199)

* Fix occasional headless issue on Linux when set to "false"

- Add a variable containing the current platform
- Check if the platform is "nt" (Windows) before closing the driver

* Update CHANGELOG.md

---------

Co-authored-by: ilike2burnthing <59480337+ilike2burnthing@users.noreply.github.com>
This commit is contained in:
21hsmw
2024-05-24 16:33:46 +00:00
committed by GitHub
parent 5a2c61601e
commit 6c1d78cb84
8 changed files with 29 additions and 10 deletions

View File

@@ -101,6 +101,9 @@ if __name__ == "__main__":
logging.info(f'FlareSolverr {utils.get_flaresolverr_version()}')
logging.debug('Debug log enabled')
# Get current OS for global variable
utils.get_current_platform()
# test browser installation
flaresolverr_service.test_browser_installation()

View File

@@ -245,7 +245,8 @@ 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()
if utils.PLATFORM_VERSION == "nt":
driver.close()
driver.quit()
logging.debug('A used instance of webdriver has been destroyed')

View File

@@ -66,7 +66,8 @@ class SessionsStorage:
return False
session = self.sessions.pop(session_id)
session.driver.close()
if utils.PLATFORM_VERSION == "nt":
session.driver.close()
session.driver.quit()
return True

View File

@@ -2,6 +2,7 @@ import asyncio
from collections.abc import Mapping
from collections.abc import Sequence
from functools import wraps
import os
import logging
import threading
import time
@@ -187,5 +188,6 @@ def test():
time.sleep(10)
driver.close()
if os.name == "nt":
driver.close()
driver.quit()

View File

@@ -11,6 +11,7 @@ from selenium.webdriver.chrome.webdriver import WebDriver
import undetected_chromedriver as uc
FLARESOLVERR_VERSION = None
PLATFORM_VERSION = None
CHROME_EXE_PATH = None
CHROME_MAJOR_VERSION = None
USER_AGENT = None
@@ -38,6 +39,13 @@ def get_flaresolverr_version() -> str:
FLARESOLVERR_VERSION = json.loads(f.read())['version']
return FLARESOLVERR_VERSION
def get_current_platform() -> str:
global PLATFORM_VERSION
if PLATFORM_VERSION is not None:
return PLATFORM_VERSION
PLATFORM_VERSION = os.name
return PLATFORM_VERSION
def create_proxy_extension(proxy: dict) -> str:
parsed_url = urllib.parse.urlparse(proxy['url'])
@@ -314,7 +322,8 @@ def get_user_agent(driver=None) -> str:
raise Exception("Error getting browser User-Agent. " + str(e))
finally:
if driver is not None:
driver.close()
if PLATFORM_VERSION == "nt":
driver.close()
driver.quit()