Skip to content

Commit

Permalink
Win32 support fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yoori committed Nov 7, 2024
1 parent 2a4ee10 commit 8aff21b
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ already included within the image.

We provide a `docker-compose.yml` configuration file. Clone this repository and execute
`docker compose up -d` to start
the container. Http endpoint will be available after little delay (5-15 sec), because container install chrome of required version on start.
the container.

### From github as pip package
> **Warning**
Expand Down
4 changes: 3 additions & 1 deletion rootfs/opt/flare_bypasser/bin/FlareBypasserRun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ if [ "$CHROME_DISABLE_GPU" = true ] ; then
ADD_PARAMS="$ADD_PARAMS --disable-gpu"
fi

echo "Run server, extensions: $EXTENSION_MODULES, chrome: $(/usr/bin/chrome --version)"
echo "Run server $(pip show flare-bypasser | grep Version | awk '{print $2}'
), chrome: $(/usr/bin/chrome --version
), extensions: $EXTENSION_MODULES"

flare_bypass_server -b 0.0.0.0:8080 $EXTENSION_MODULES_PARAM $ADD_PARAMS 2>&1 | \
tee "$WORKSPACE_ROOT/log/flare_bypass_server.log"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
setup(
name='flare-bypasser',
python_requires='>= 3.9',
version='0.1.24',
version='0.1.25',
packages=["flare_bypasser"],
package_dir={
"": ".",
Expand Down
17 changes: 11 additions & 6 deletions src/flare_bypasser/browser_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys
import typing
import asyncio
import uuid
Expand Down Expand Up @@ -55,23 +56,27 @@ def __init__(self, nodriver_driver: nodriver.Browser):

@staticmethod
def start_xvfb_display():
global XVFB_DISPLAY
if XVFB_DISPLAY is None:
from xvfbwrapper import Xvfb
XVFB_DISPLAY = Xvfb()
XVFB_DISPLAY.start()
if sys.platform != 'win32':
global XVFB_DISPLAY
if XVFB_DISPLAY is None:
from xvfbwrapper import Xvfb
XVFB_DISPLAY = Xvfb()
XVFB_DISPLAY.start()

@staticmethod
async def create(proxy = None, disable_gpu = False):
BrowserWrapper.start_xvfb_display()
browser_args = []
if proxy:
browser_args.append("--proxy-server=" + proxy)
if disable_gpu :
if disable_gpu:
browser_args += [
"--disable-gpu",
"--disable-software-rasterizer"
]
if sys.platform == 'win32':
browser_args += ["--headless"]

nodriver_driver = await nodriver.start(
sandbox=False,
browser_args=browser_args
Expand Down
3 changes: 2 additions & 1 deletion src/flare_bypasser/flare_bypass_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
'disable_gpu': False
}


class HandleCommandResponseSolution(pydantic.BaseModel):
status: str
url: str
Expand Down Expand Up @@ -390,7 +391,7 @@ def server_run():
end_port=args.proxy_listen_end_port,
command=args.proxy_command)

if args.disable_gpu :
if args.disable_gpu:
solver_args['disable_gpu'] = True

if USE_GUNICORN:
Expand Down
22 changes: 16 additions & 6 deletions src/flare_bypasser/flare_bypasser.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ async def solve(self, req: Request) -> Response:
return res

async def _resolve_challenge(self, req: Request) -> Response:
start_time = datetime.datetime.now()
start_time: datetime.datetime = datetime.datetime.now()
step = 'start'
try:
use_proxy = (req.proxy if req.proxy else self._proxy)
use_proxy: str = (req.proxy if req.proxy else self._proxy)
proxy_holder = None

step = 'proxy init'
Expand All @@ -245,10 +245,12 @@ async def _resolve_challenge(self, req: Request) -> Response:
else:
proxy_holder = contextlib.nullcontext()

step = 'solving'
with proxy_holder:
try:
self._driver = await BrowserWrapper.create(use_proxy, disable_gpu = self._disable_gpu)
step = 'browser init'
self._driver: BrowserWrapper = await BrowserWrapper.create(
use_proxy, disable_gpu = self._disable_gpu
)
logging.info(
'New instance of webdriver has been created to perform the request (proxy=' +
str(use_proxy) + '), timeout=' + str(req.max_timeout))
Expand All @@ -260,11 +262,19 @@ async def _resolve_challenge(self, req: Request) -> Response:
self._driver = None
logging.debug('A used instance of webdriver has been destroyed')
except Solver.Exception as e:
error_message = "Error solving the challenge. On step '" + str(e.step) + "': " + str(e).replace('\n', '\\n')
error_message = (
"Error solving the challenge. On platform " + str(sys.platform) +
" at step '" + str(e.step) + "': " +
str(e).replace('\n', '\\n')
)
logging.error(error_message)
raise Solver.Exception(error_message, step=e.step)
except Exception as e:
error_message = "Error solving the challenge. On step '" + step + "': " + str(e).replace('\n', '\\n')
error_message = (
"Error solving the challenge. On platform " + str(sys.platform) +
" at step '" + step + "': " +
str(e).replace('\n', '\\n')
)
logging.error(error_message)
raise Solver.Exception(error_message)

Expand Down
2 changes: 2 additions & 0 deletions src/tests/unit_tests/proxy_controller_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from flare_bypasser import ProxyController


def test_two_different_proxies_rent():
proxy_controller = ProxyController(command = 'echo "Listening on {{LOCAL_PORT}}"')

Expand All @@ -10,6 +11,7 @@ def test_two_different_proxies_rent():

assert proxy_controller.opened_proxies_count() == 0


def test_two_equal_proxies_rent():
proxy_controller = ProxyController(command = 'echo "Listening on {{LOCAL_PORT}}"')

Expand Down
8 changes: 6 additions & 2 deletions utils/linux_chrome_installer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys
import shutil
import logging
import json
Expand All @@ -10,6 +11,7 @@
def fetch_package(download_url):
return urlretrieve(download_url)[0]


def unzip_package(
fp, extract_root='/', unzip_path='/tmp/unzip_chrome',
extract_sub_directory=''
Expand Down Expand Up @@ -89,6 +91,8 @@ def download_and_install(version_prefix = None, install_root = None):
try:
res = download_and_install(
version_prefix = args.version_prefix,
install_root = args.install_root)
except Exception as e :
install_root = args.install_root
)
except Exception as e:
logging.error("Can't install chrome: " + str(e))
sys.exit(1)

0 comments on commit 8aff21b

Please sign in to comment.