Stabilize recorded Chrome startup
This commit is contained in:
+11
-6
@@ -91,7 +91,6 @@ def _build_options(
|
|||||||
chrome_binary: str,
|
chrome_binary: str,
|
||||||
profile_dir: str | None = None,
|
profile_dir: str | None = None,
|
||||||
display: str | None = None,
|
display: str | None = None,
|
||||||
initial_url: str | None = None,
|
|
||||||
) -> Options:
|
) -> Options:
|
||||||
opts = Options()
|
opts = Options()
|
||||||
opts.binary_location = chrome_binary
|
opts.binary_location = chrome_binary
|
||||||
@@ -108,14 +107,17 @@ def _build_options(
|
|||||||
opts.add_argument(f"--user-agent={user_agent}")
|
opts.add_argument(f"--user-agent={user_agent}")
|
||||||
opts.add_argument("--no-sandbox")
|
opts.add_argument("--no-sandbox")
|
||||||
opts.add_argument("--disable-gpu")
|
opts.add_argument("--disable-gpu")
|
||||||
|
opts.add_argument("--disable-logging")
|
||||||
|
opts.add_argument("--no-first-run")
|
||||||
|
opts.add_argument("--no-default-browser-check")
|
||||||
|
opts.add_argument("--disable-background-networking")
|
||||||
|
opts.add_argument("--disable-component-update")
|
||||||
|
opts.add_argument("--disable-default-apps")
|
||||||
|
opts.add_argument("--disable-sync")
|
||||||
opts.add_argument("--renderer-process-limit=2")
|
opts.add_argument("--renderer-process-limit=2")
|
||||||
opts.add_argument("--disable-blink-features=AutomationControlled")
|
opts.add_argument("--disable-blink-features=AutomationControlled")
|
||||||
opts.add_argument("--disable-infobars")
|
opts.add_argument("--disable-infobars")
|
||||||
opts.add_argument("--window-size=1920,1080")
|
opts.add_argument("--window-size=1920,1080")
|
||||||
if initial_url and initial_url.startswith(("http://", "https://")):
|
|
||||||
# Opening the configured page as a Chrome process argument avoids
|
|
||||||
# waiting for the initial New Tab renderer before navigation begins.
|
|
||||||
opts.add_argument(initial_url)
|
|
||||||
return opts
|
return opts
|
||||||
|
|
||||||
|
|
||||||
@@ -135,7 +137,6 @@ def make_driver(
|
|||||||
chrome_binary,
|
chrome_binary,
|
||||||
profile_dir,
|
profile_dir,
|
||||||
display,
|
display,
|
||||||
initial_url,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
log.info(
|
log.info(
|
||||||
@@ -150,6 +151,10 @@ def make_driver(
|
|||||||
driver_executable_path=_local_driver_path(),
|
driver_executable_path=_local_driver_path(),
|
||||||
version_main=major,
|
version_main=major,
|
||||||
use_subprocess=True,
|
use_subprocess=True,
|
||||||
|
# undetected-chromedriver captures Chrome stdout/stderr in pipes but
|
||||||
|
# does not drain them. Fatal-only logging prevents a full pipe from
|
||||||
|
# freezing Chrome during renderer startup in Docker.
|
||||||
|
log_level=3,
|
||||||
)
|
)
|
||||||
log.info("ChromeDriver connected")
|
log.info("ChromeDriver connected")
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -77,7 +77,9 @@ services:
|
|||||||
redis:
|
redis:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
# Chrome needs extra shared memory to avoid OOM crashes
|
# Chrome needs extra shared memory to avoid OOM crashes
|
||||||
shm_size: "512mb"
|
# Headful Chromium recording needs substantially more shared memory than
|
||||||
|
# headless mode. This is a limit, not an up-front RAM allocation.
|
||||||
|
shm_size: "2gb"
|
||||||
cap_add:
|
cap_add:
|
||||||
- SYS_ADMIN
|
- SYS_ADMIN
|
||||||
security_opt:
|
security_opt:
|
||||||
|
|||||||
Reference in New Issue
Block a user