fix: optimize browser memory

This commit is contained in:
zhayujie
2026-05-28 19:09:26 +08:00
parent b7b8e3679c
commit 136b0b89e8
2 changed files with 27 additions and 1 deletions

View File

@@ -15,7 +15,7 @@ import threading
from typing import Optional, Dict, Any, List, Callable from typing import Optional, Dict, Any, List, Callable
from common.log import logger from common.log import logger
from common.utils import expand_path from common.utils import expand_path, is_cloud_deployment
_DEFAULT_USER_DATA_DIR = "~/.cow/browser_profile" _DEFAULT_USER_DATA_DIR = "~/.cow/browser_profile"
@@ -436,6 +436,20 @@ class BrowserService:
if self._headless: if self._headless:
launch_args.append("--no-sandbox") launch_args.append("--no-sandbox")
if is_cloud_deployment():
launch_args.extend([
"--disable-gpu",
"--disable-software-rasterizer",
"--disable-extensions",
"--disable-background-networking",
"--disable-background-timer-throttling",
"--disable-renderer-backgrounding",
"--disable-features=site-per-process,TranslateUI,IsolateOrigins",
"--no-zygote",
"--js-flags=--max-old-space-size=384",
"--memory-pressure-off",
])
extra_args = self._config.get("launch_args", []) extra_args = self._config.get("launch_args", [])
if extra_args: if extra_args:
launch_args.extend(extra_args) launch_args.extend(extra_args)

View File

@@ -117,6 +117,18 @@ def expand_path(path: str) -> str:
return expanded return expanded
def is_cloud_deployment() -> bool:
if os.environ.get("CLOUD_DEPLOYMENT_ID"):
return True
try:
from config import conf
if conf().get("cloud_deployment_id"):
return True
except Exception:
pass
return False
def get_cloud_headers(api_key: str) -> dict: def get_cloud_headers(api_key: str) -> dict:
""" """
Build standard headers for LinkAI API requests, Build standard headers for LinkAI API requests,