1414
1515from app_types .payload import ItemPayload
1616from app_types .vinted import VintedPackageSize
17+ from config import get_settings
1718from services .os_service import get_project_root
1819from services .timer_service import TimerService
1920
@@ -88,12 +89,23 @@ def _normalize_vinted_label(text: str) -> str:
8889 )
8990
9091
91- _DEFAULT_BROWSER_ARGS : list [str ] = [
92- "--no-sandbox" ,
93- "--disable-blink-features=AutomationControlled" ,
94- "--disable-features=IsolateOrigins,site-per-process" ,
95- "--start-maximized" ,
96- ]
92+ def _build_browser_args (* , headless : bool ) -> list [str ]:
93+ """Flags communs ; en headless (prod VPS) on évite --start-maximized et on renforce la stabilité serveur."""
94+ base : list [str ] = [
95+ "--no-sandbox" ,
96+ "--disable-blink-features=AutomationControlled" ,
97+ "--disable-features=IsolateOrigins,site-per-process" ,
98+ ]
99+ if headless :
100+ base .extend (
101+ [
102+ "--window-size=1920,1080" ,
103+ "--disable-dev-shm-usage" ,
104+ ]
105+ )
106+ else :
107+ base .append ("--start-maximized" )
108+ return base
97109
98110
99111class VintedService :
@@ -119,11 +131,16 @@ async def init_browser(cls) -> None:
119131 Raises:
120132 RuntimeError: If the browser failed to start.
121133 """
122- cls ._browser = await uc .start (
123- headless = False ,
124- browser_args = list (_DEFAULT_BROWSER_ARGS ),
125- sandbox = False ,
126- )
134+ settings = get_settings ()
135+ headless = settings .vinted_browser_headless
136+ start_kw : dict [str , Any ] = {
137+ "headless" : headless ,
138+ "browser_args" : _build_browser_args (headless = headless ),
139+ "sandbox" : False ,
140+ }
141+ if settings .vinted_chrome_executable :
142+ start_kw ["browser_executable_path" ] = settings .vinted_chrome_executable .strip ()
143+ cls ._browser = await uc .start (** start_kw )
127144 if cls ._browser is None :
128145 raise RuntimeError ("nodriver.start() returned no browser instance" )
129146
0 commit comments