Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix(downloaders): check robots.txt in plain-Playwright fallback (#8066) (#8069)

HPH Proton12e10da85892
diff --git a/changelog.d/8066.bugfix.md b/changelog.d/8066.bugfix.md
new file mode 100644
index 0000000000..356466c54a
--- /dev/null
+++ b/changelog.d/8066.bugfix.md
@@ -0,0 +1 @@
+Check robots.txt via the guarded session before fetching with the plain-Playwright fallback when Crawl4AI is unavailable or fails.
diff --git a/src/local_deep_research/research_library/downloaders/playwright_html.py b/src/local_deep_research/research_library/downloaders/playwright_html.py
index 120ce2dc94..398f3d7d7c 100644
--- a/src/local_deep_research/research_library/downloaders/playwright_html.py
+++ b/src/local_deep_research/research_library/downloaders/playwright_html.py
@@ -1170,6 +1170,12 @@ class PlaywrightHTMLDownloader(HTMLDownloader):
def _fetch_with_playwright(self, url: str) -> Optional[str]:
"""Fetch HTML using plain Playwright (fallback)."""
+ if not self._robots_allows(url):
+ logger.info(
+ "Playwright: blocked by robots.txt for {}",
+ ssrf_validator.redact_url_for_log(url),
+ )
+ return None
logger.debug(
"playwright.fetch_started url={url}",
url=redact_url_for_log(url),
diff --git a/tests/research_library/downloaders/test_html_logging_sinks.py b/tests/research_library/downloaders/test_html_logging_sinks.py
index 88b3e33895..1418a960d5 100644
--- a/tests/research_library/downloaders/test_html_logging_sinks.py
+++ b/tests/research_library/downloaders/test_html_logging_sinks.py
@@ -334,6 +334,9 @@ def test_playwright_branches_render_safe_events(
page.content.return_value = content
_install_playwright(monkeypatch, page)
downloader = PlaywrightHTMLDownloader()
+ # Close the robots.txt network seam: the real check fetches
+ # ``/robots.txt`` through SafeSession before the key is applied.
+ monkeypatch.setattr(downloader, "_robots_allows", lambda _url: True)
downloader.rate_tracker = MagicMock()
downloader.rate_tracker.apply_rate_limit.return_value = 0
@@ -461,6 +464,9 @@ def _drive_playwright(url, monkeypatch):
page.content.return_value = "<html>ok</html>"
_install_playwright(monkeypatch, page)
downloader = PlaywrightHTMLDownloader()
+ # Close the robots.txt network seam: the real check fetches
+ # ``/robots.txt`` through SafeSession before the key is applied.
+ monkeypatch.setattr(downloader, "_robots_allows", lambda _url: True)
downloader.rate_tracker = MagicMock()
downloader.rate_tracker.apply_rate_limit.return_value = 0
with downloader:
diff --git a/tests/research_library/downloaders/test_playwright_html_guards.py b/tests/research_library/downloaders/test_playwright_html_guards.py
index d3f2fb5814..367abae233 100644
--- a/tests/research_library/downloaders/test_playwright_html_guards.py
+++ b/tests/research_library/downloaders/test_playwright_html_guards.py
@@ -16,11 +16,16 @@ import asyncio
import builtins
from unittest.mock import MagicMock, patch
+import pytest
from local_deep_research.research_library.downloaders.playwright_html import (
PlaywrightHTMLDownloader,
_run_async,
)
+from local_deep_research.security.egress.policy import (
+ Decision,
+ PolicyDeniedError,
+)
class TestRunAsyncEventLoopHandling:
@@ -87,6 +92,9 @@ class TestPlaywrightImportErrorGuard:
# Mock rate_tracker to avoid needing the full rate-limit setup.
dl.rate_tracker = MagicMock()
dl.rate_tracker.apply_rate_limit.return_value = 0
+ # Stub the guarded robots.txt check so this unit test does not
+ # fetch https://example.com/robots.txt.
+ dl._robots_allows = MagicMock(return_value=True)
with patch.object(
builtins,
"__import__",
@@ -96,3 +104,98 @@ class TestPlaywrightImportErrorGuard:
assert result is None
finally:
dl.close()
+
+
+_PRIVATE_URL = "https://example.com/private"
+_ROBOTS_DISALLOW_PRIVATE = "User-agent: *\nDisallow: /private\n"
+
+
+def _assert_playwright_not_started(sync_pw):
+ """The patched Playwright entry point never launched or opened a page."""
+ sync_pw.assert_not_called()
+ browser = (
+ sync_pw.return_value.start.return_value.chromium.launch.return_value
+ )
+ browser.new_page.assert_not_called()
+
+
+class TestPlainPlaywrightRobotsCheck:
+ """The plain-Playwright fetcher honors robots.txt before any browser work.
+
+ Crawl4AI refuses a disallowed URL and does not fall through. When
+ Crawl4AI is missing, or a caller invokes the Playwright fetcher
+ directly, the same disallow must skip the browser and the rate limit.
+ """
+
+ def _downloader(self):
+ dl = PlaywrightHTMLDownloader(timeout=5)
+ dl.rate_tracker = MagicMock()
+ dl.rate_tracker.apply_rate_limit.return_value = 0
+ return dl
+
+ def test_disallow_returns_none_without_browser_or_rate_limit(self):
+ """A robots.txt Disallow stops the plain-Playwright fetch."""
+ dl = self._downloader()
+ robots = MagicMock(status_code=200, text=_ROBOTS_DISALLOW_PRIVATE)
+ try:
+ with (
+ patch.object(dl.session, "get", return_value=robots) as get,
+ patch("playwright.sync_api.sync_playwright") as sync_pw,
+ ):
+ result = dl._fetch_with_playwright(_PRIVATE_URL)
+ finally:
+ dl.close()
+
+ assert result is None
+ get.assert_called_once_with(
+ "https://example.com/robots.txt",
+ timeout=5,
+ allow_redirects=True,
+ )
+ dl.rate_tracker.apply_rate_limit.assert_not_called()
+ _assert_playwright_not_started(sync_pw)
+
+ def test_fetch_html_fallback_honors_disallow_when_crawl4ai_missing(self):
+ """With Crawl4AI unavailable, the fallback still obeys robots.txt."""
+ dl = self._downloader()
+ robots = MagicMock(status_code=200, text=_ROBOTS_DISALLOW_PRIVATE)
+ try:
+ with (
+ patch("playwright.sync_api.sync_playwright") as sync_pw,
+ patch.object(dl.session, "get", return_value=robots) as get,
+ patch.object(
+ builtins,
+ "__import__",
+ side_effect=_import_blocker("crawl4ai"),
+ ),
+ ):
+ result = dl._fetch_html(_PRIVATE_URL)
+ finally:
+ dl.close()
+
+ assert result is None
+ get.assert_called_once_with(
+ "https://example.com/robots.txt",
+ timeout=5,
+ allow_redirects=True,
+ )
+ dl.rate_tracker.apply_rate_limit.assert_not_called()
+ _assert_playwright_not_started(sync_pw)
+
+ def test_policy_denied_propagates_without_browser_or_rate_limit(self):
+ """A policy denial from the robots check is not swallowed."""
+ dl = self._downloader()
+ denied = PolicyDeniedError(
+ Decision(False, "scope_mismatch"), _PRIVATE_URL
+ )
+ dl._robots_allows = MagicMock(side_effect=denied)
+ try:
+ with patch("playwright.sync_api.sync_playwright") as sync_pw:
+ with pytest.raises(PolicyDeniedError) as raised:
+ dl._fetch_with_playwright(_PRIVATE_URL)
+ finally:
+ dl.close()
+
+ assert raised.value.decision.reason == "scope_mismatch"
+ dl.rate_tracker.apply_rate_limit.assert_not_called()
+ _assert_playwright_not_started(sync_pw)
diff --git a/tests/research_library/downloaders/test_playwright_html_ssrf_guard.py b/tests/research_library/downloaders/test_playwright_html_ssrf_guard.py
index f55b974ef3..79c65160b4 100644
--- a/tests/research_library/downloaders/test_playwright_html_ssrf_guard.py
+++ b/tests/research_library/downloaders/test_playwright_html_ssrf_guard.py
@@ -1741,6 +1741,9 @@ class TestPlainPlaywrightWebRTCContextScope:
dl = PlaywrightHTMLDownloader(timeout=5)
dl.rate_tracker = MagicMock()
dl.rate_tracker.apply_rate_limit.return_value = 0
+ # Stub the guarded robots.txt check so this unit test does not
+ # fetch https://example.com/robots.txt.
+ dl._robots_allows = MagicMock(return_value=True)
mock_page = MagicMock()
mock_page.content.return_value = "<html><body>ok</body></html>"
@@ -1789,6 +1792,9 @@ class TestPlainPlaywrightWebRTCContextScope:
dl = PlaywrightHTMLDownloader(timeout=5)
dl.rate_tracker = MagicMock()
dl.rate_tracker.apply_rate_limit.return_value = 0
+ # Stub the guarded robots.txt check so this unit test does not
+ # fetch https://example.com/robots.txt.
+ dl._robots_allows = MagicMock(return_value=True)
mock_page = MagicMock()
mock_page.content.return_value = "<html><body>ok</body></html>"