Coverage for src/local_deep_research/utilities/js_rendering.py: 100%

5 statements  

« prev     ^ index     » next       coverage.py v7.14.1, created at 2026-06-03 23:15 +0000

1"""Shared accessor for the ``web.enable_javascript_rendering`` setting. 

2 

3The setting is read from a thread-local settings context (set on the 

4research's main thread) or from an explicit snapshot dict (passed 

5through closures so it works on LangGraph ``ToolNode`` worker threads 

6where ``threading.local()`` state from the research thread does not 

7propagate). Defaults to ``False`` when neither is available. 

8 

9Why disabled by default: the production Docker image ships without 

10Chromium, so the headless-browser fallback (Crawl4AI/Playwright) 

11cannot succeed for the majority of users; before this gate landed each 

12attempt failed loudly and contributed to the memory growth reported 

13in issue #3826. In limited (mostly accidental) internal benchmark 

14comparisons between dev instances that happened to have Chromium 

15installed and routine Docker runs that did not, JS rendering did not 

16measurably improve research quality, and most regular benchmark runs 

17are on Docker without Chromium anyway. Users who specifically need 

18JS rendering can install Chromium (``playwright install --with-deps 

19chromium``) and toggle the setting in the UI. 

20""" 

21 

22from __future__ import annotations 

23 

24from typing import Optional 

25 

26from ..config.thread_settings import get_bool_setting_from_snapshot 

27 

28 

29def read_js_rendering_setting(settings_snapshot: Optional[dict]) -> bool: 

30 """Return the current value of ``web.enable_javascript_rendering``. 

31 

32 Args: 

33 settings_snapshot: Optional dict captured at the boundary where 

34 the calling code crosses into a worker thread. Pass the 

35 strategy's ``self.settings_snapshot`` if available; pass 

36 ``None`` when the caller has no snapshot — the helper will 

37 try thread-local context and finally fall back to ``False``. 

38 

39 Returns: 

40 ``True`` only when the setting is explicitly enabled. ``bool(...)`` 

41 coerces ``Any`` to a definite bool for mypy ``warn_return_any``. 

42 """ 

43 return bool( 

44 get_bool_setting_from_snapshot( 

45 "web.enable_javascript_rendering", 

46 default=False, 

47 settings_snapshot=settings_snapshot, 

48 ) 

49 )