integration with CloakBrowser
This commit is contained in:
parent
b90fb85ab3
commit
f45b81aff1
6 changed files with 158 additions and 25 deletions
|
|
@ -16,6 +16,12 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|||
procps \
|
||||
curl \
|
||||
ca-certificates \
|
||||
fonts-noto-color-emoji \
|
||||
fonts-freefont-ttf \
|
||||
fonts-unifont \
|
||||
fonts-ipafont-gothic \
|
||||
fonts-wqy-zenhei \
|
||||
fonts-tlwg-loma-otf \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /src
|
||||
|
|
@ -23,12 +29,16 @@ RUN mkdir -p /src/browser_data
|
|||
|
||||
RUN python3 -m pip install --no-cache-dir --break-system-packages \
|
||||
"browser-use>=0.12.5" \
|
||||
"langchain-openai>=0.3.0"
|
||||
"langchain-openai>=0.3.0" \
|
||||
"cloakbrowser[geoip]>=0.3.0"
|
||||
|
||||
RUN python3 -m cloakbrowser install
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
COPY cloak_browser_launcher.py /src/cloak_browser_launcher.py
|
||||
COPY browser_use_runner.py /src/browser_use_runner.py
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
||||
EXPOSE 6080 9222 8787
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
|
|
|
|||
|
|
@ -614,7 +614,7 @@ async def run_browser_task(task, run_id=None):
|
|||
|
||||
try:
|
||||
logger.info("Creating Browser...")
|
||||
_append_event(run_id, "setup", "Подключаюсь к Chromium через CDP.")
|
||||
_append_event(run_id, "setup", "Подключаюсь к браузеру через CDP.")
|
||||
browser = Browser(cdp_url=cdp_url)
|
||||
logger.info("Browser created")
|
||||
except Exception as err:
|
||||
|
|
|
|||
62
browser_env/cloak_browser_launcher.py
Normal file
62
browser_env/cloak_browser_launcher.py
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import asyncio
|
||||
import os
|
||||
import shlex
|
||||
import signal
|
||||
|
||||
from cloakbrowser import launch_async
|
||||
|
||||
|
||||
def _env_bool(name, default):
|
||||
raw = os.getenv(name)
|
||||
if raw is None:
|
||||
return default
|
||||
return raw.strip().lower() in {"1", "true", "yes", "on"}
|
||||
|
||||
|
||||
async def main():
|
||||
debug_port = os.getenv("CHROME_LOCAL_DEBUG_PORT", "9223")
|
||||
args = [
|
||||
f"--remote-debugging-port={debug_port}",
|
||||
"--remote-debugging-address=127.0.0.1",
|
||||
"--remote-allow-origins=*",
|
||||
"--window-size=1280,720",
|
||||
"--no-sandbox",
|
||||
"--disable-dev-shm-usage",
|
||||
"--ozone-platform=x11",
|
||||
]
|
||||
extra_args = os.getenv("CLOAK_ARGS", "").strip()
|
||||
if extra_args:
|
||||
args.extend(shlex.split(extra_args))
|
||||
|
||||
launch_kwargs = {
|
||||
"headless": _env_bool("CLOAK_HEADLESS", False),
|
||||
"humanize": _env_bool("CLOAK_HUMANIZE", True),
|
||||
"args": args,
|
||||
}
|
||||
|
||||
if launch_kwargs["humanize"]:
|
||||
launch_kwargs["human_preset"] = os.getenv("CLOAK_HUMAN_PRESET", "default")
|
||||
|
||||
proxy = os.getenv("CLOAK_PROXY", "").strip()
|
||||
if proxy:
|
||||
launch_kwargs["proxy"] = proxy
|
||||
|
||||
if _env_bool("CLOAK_GEOIP", False):
|
||||
launch_kwargs["geoip"] = True
|
||||
|
||||
browser = await launch_async(**launch_kwargs)
|
||||
print(f"CloakBrowser started on 127.0.0.1:{debug_port}", flush=True)
|
||||
|
||||
stop_event = asyncio.Event()
|
||||
loop = asyncio.get_running_loop()
|
||||
for sig in (signal.SIGINT, signal.SIGTERM):
|
||||
loop.add_signal_handler(sig, stop_event.set)
|
||||
|
||||
try:
|
||||
await stop_event.wait()
|
||||
finally:
|
||||
await browser.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
|
|
@ -11,6 +11,7 @@ CHROME_LOCAL_DEBUG_PORT="${CHROME_LOCAL_DEBUG_PORT:-9223}"
|
|||
CHROME_PUBLIC_DEBUG_PORT="${CHROME_PUBLIC_DEBUG_PORT:-9222}"
|
||||
BROWSER_USE_RPC_PORT="${BROWSER_USE_RPC_PORT:-8787}"
|
||||
CHROME_PROFILE_DIR="${CHROME_PROFILE_DIR:-/src/browser_data}"
|
||||
BROWSER_ENGINE="${BROWSER_ENGINE:-chromium}"
|
||||
|
||||
MAX_RESTARTS="${MAX_RESTARTS:-10}"
|
||||
RESTART_WINDOW_SEC="${RESTART_WINDOW_SEC:-60}"
|
||||
|
|
@ -147,26 +148,38 @@ while true; do
|
|||
|
||||
rm -f "${CHROME_PROFILE_DIR}/SingletonLock" "${CHROME_PROFILE_DIR}/SingletonCookie" "${CHROME_PROFILE_DIR}/SingletonSocket" 2>/dev/null || true
|
||||
|
||||
log "starting Chromium (local DevTools:${CHROME_LOCAL_DEBUG_PORT})"
|
||||
chromium \
|
||||
--no-sandbox \
|
||||
--disable-dev-shm-usage \
|
||||
--ozone-platform=x11 \
|
||||
--remote-debugging-port="${CHROME_LOCAL_DEBUG_PORT}" \
|
||||
--remote-debugging-address=127.0.0.1 \
|
||||
--remote-allow-origins='*' \
|
||||
--window-size=1280,720 \
|
||||
--user-data-dir="${CHROME_PROFILE_DIR}" \
|
||||
--disable-blink-features=AutomationControlled \
|
||||
--no-first-run \
|
||||
--disable-gpu \
|
||||
--mute-audio \
|
||||
--no-default-browser-check \
|
||||
--disable-software-rasterizer \
|
||||
--disable-features=site-per-process \
|
||||
--disable-crash-reporter \
|
||||
--disable-extensions \
|
||||
--disable-sync &
|
||||
case "${BROWSER_ENGINE,,}" in
|
||||
chromium)
|
||||
log "starting Chromium (local DevTools:${CHROME_LOCAL_DEBUG_PORT})"
|
||||
chromium \
|
||||
--no-sandbox \
|
||||
--disable-dev-shm-usage \
|
||||
--ozone-platform=x11 \
|
||||
--remote-debugging-port="${CHROME_LOCAL_DEBUG_PORT}" \
|
||||
--remote-debugging-address=127.0.0.1 \
|
||||
--remote-allow-origins='*' \
|
||||
--window-size=1280,720 \
|
||||
--user-data-dir="${CHROME_PROFILE_DIR}" \
|
||||
--disable-blink-features=AutomationControlled \
|
||||
--no-first-run \
|
||||
--disable-gpu \
|
||||
--mute-audio \
|
||||
--no-default-browser-check \
|
||||
--disable-software-rasterizer \
|
||||
--disable-features=site-per-process \
|
||||
--disable-crash-reporter \
|
||||
--disable-extensions \
|
||||
--disable-sync &
|
||||
;;
|
||||
cloak|cloakbrowser)
|
||||
log "starting CloakBrowser (local DevTools:${CHROME_LOCAL_DEBUG_PORT})"
|
||||
python3 -u /src/cloak_browser_launcher.py &
|
||||
;;
|
||||
*)
|
||||
log "fatal: unsupported BROWSER_ENGINE=${BROWSER_ENGINE}; expected chromium or cloak"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
CHROME_PID=$!
|
||||
wait "$CHROME_PID" || CHROME_EXIT=$?
|
||||
|
|
@ -183,7 +196,7 @@ while true; do
|
|||
fi
|
||||
|
||||
RESTART_COUNT=$((RESTART_COUNT + 1))
|
||||
log "Chromium exited with code=${CHROME_EXIT}; restart ${RESTART_COUNT}/${MAX_RESTARTS} in current window"
|
||||
log "${BROWSER_ENGINE} exited with code=${CHROME_EXIT}; restart ${RESTART_COUNT}/${MAX_RESTARTS} in current window"
|
||||
|
||||
if [ "$RESTART_COUNT" -ge "$MAX_RESTARTS" ]; then
|
||||
log "fatal: too many Chromium restarts in ${RESTART_WINDOW_SEC}s"
|
||||
|
|
@ -194,4 +207,3 @@ while true; do
|
|||
unset CHROME_EXIT
|
||||
unset CHROME_PID
|
||||
done
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue