Skip to content

Commit

Permalink
Fix occasional headless issue on Linux when set to "false" (#1199)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
21hsmw and ilike2burnthing committed May 24, 2024
1 parent 5a2c616 commit 6c1d78c
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v3.3.19 (2024/05/23)
* Fix occasional headless issue on Linux when set to "false". Thanks @21hsmw

## v3.3.18 (2024/05/20)

* Fix LANG ENV for Linux
Expand Down
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["/usr/local/bin/python", "-u", "/app/flaresolverr.py"]

# Local build
# docker build -t ngosang/flaresolverr:3.3.18 .
# docker run -p 8191:8191 ngosang/flaresolverr:3.3.18
# docker build -t ngosang/flaresolverr:3.3.19 .
# docker run -p 8191:8191 ngosang/flaresolverr:3.3.19

# Multi-arch build
# docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
# docker buildx create --use
# docker buildx build -t ngosang/flaresolverr:3.3.18 --platform linux/386,linux/amd64,linux/arm/v7,linux/arm64/v8 .
# docker buildx build -t ngosang/flaresolverr:3.3.19 --platform linux/386,linux/amd64,linux/arm/v7,linux/arm64/v8 .
# add --push to publish in DockerHub

# Test multi-arch build
# docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
# docker buildx create --use
# docker buildx build -t ngosang/flaresolverr:3.3.18 --platform linux/arm/v7 --load .
# docker run -p 8191:8191 --platform linux/arm/v7 ngosang/flaresolverr:3.3.18
# docker buildx build -t ngosang/flaresolverr:3.3.19 --platform linux/arm/v7 --load .
# docker run -p 8191:8191 --platform linux/arm/v7 ngosang/flaresolverr:3.3.19
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flaresolverr",
"version": "3.3.18",
"version": "3.3.19",
"description": "Proxy server to bypass Cloudflare protection",
"author": "Diego Heras (ngosang / ngosang@hotmail.es)",
"license": "MIT"
Expand Down
3 changes: 3 additions & 0 deletions src/flaresolverr.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ def controller_v1():
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()

Expand Down
3 changes: 2 additions & 1 deletion src/flaresolverr_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
3 changes: 2 additions & 1 deletion src/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def destroy(self, session_id: str) -> bool:
return False

session = self.sessions.pop(session_id)
session.driver.close()
if utils.PLATFORM_VERSION == "nt":
session.driver.close()
session.driver.quit()
return True

Expand Down
4 changes: 3 additions & 1 deletion src/undetected_chromedriver/devtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from collections.abc import Mapping
from collections.abc import Sequence
from functools import wraps
import os
import logging
import threading
import time
Expand Down Expand Up @@ -187,5 +188,6 @@ def wrapped(*args, **kwargs):

time.sleep(10)

driver.close()
if os.name == "nt":
driver.close()
driver.quit()
11 changes: 10 additions & 1 deletion src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import undetected_chromedriver as uc

FLARESOLVERR_VERSION = None
PLATFORM_VERSION = None
CHROME_EXE_PATH = None
CHROME_MAJOR_VERSION = None
USER_AGENT = None
Expand Down Expand Up @@ -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'])
Expand Down Expand Up @@ -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()


Expand Down

1 comment on commit 6c1d78c

@ilike2burnthing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.