Dockerfile 部署

This commit is contained in:
hjq
2026-06-12 16:51:03 +08:00
parent 6216548971
commit 59a6571707
4 changed files with 18 additions and 2 deletions

View File

@@ -42,10 +42,13 @@ def dump_page_state(page: ChromiumPage, label: str = ""):
# ── 浏览器 ────────────────────────────────────────────────────────────────────
def get_page(headless: bool = False, port: int = 9222) -> ChromiumPage:
co = ChromiumOptions()
if headless:
# 强制在生产环境下使用无头模式
is_docker = os.path.exists('/.dockerenv')
if headless or is_docker:
co.set_argument("--headless=new")
co.set_argument("--disable-blink-features=AutomationControlled")
co.set_argument("--no-sandbox")
co.set_argument("--disable-dev-shm-usage") # 增加这个参数防止容器内存不足
co.set_argument("--window-size=1440,900")
co.set_local_port(port)
return ChromiumPage(co)