fix: disable Firefox JSON viewer so evaluate works on JSON APIs

Firefox renders application/json documents in a built-in viewer whose own
CSP (<script-src resource:>) blocks Playwright's eval-based page.evaluate,
crashing /v1 with a 500 on JSON APIs (closes #394). Setting
devtools.jsonview.enabled=false renders JSON as plain text, which also
returns the raw JSON body instead of the viewer's syntax-highlighted HTML.
This commit is contained in:
ThePhaseless
2026-08-11 11:08:04 +02:00
parent f8d087bab8
commit 46a3c68eb0
2 changed files with 34 additions and 0 deletions
+6
View File
@@ -96,6 +96,12 @@ async def get_browser(
proxy=proxy_config,
humanize=True,
locale=BROWSER_LOCALE or "auto",
# Firefox renders application/json documents in a built-in viewer whose
# own CSP (`script-src resource:`) blocks Playwright's eval-based
# evaluate(), crashing /v1 on JSON APIs (issue #394). Disabling the
# viewer renders JSON as plain text: evaluate works and consumers get
# the raw JSON instead of the viewer's HTML markup.
extra_prefs={"devtools.jsonview.enabled": False},
) as browser_raw:
# InvisiblePlaywright yields a Browser instance
browser = cast("Browser", browser_raw)
+28
View File
@@ -58,6 +58,34 @@ def test_bypass(website: str):
assert response.status_code == HTTPStatus.OK
def test_json_api():
"""JSON APIs must return 200, not crash on the UA evaluate.
Firefox renders application/json in a built-in viewer whose CSP blocks
Playwright's eval-based evaluate() (issue #394). The browser must be
launched with the viewer disabled so /v1 works and returns the raw JSON.
"""
url = "https://api.ipify.org?format=json"
test_request = httpx2.get(url)
if test_request.status_code >= HTTPStatus.INTERNAL_SERVER_ERROR:
pytest.skip(
f"Skipping JSON API test - upstream error ({test_request.status_code})"
)
response = client.post(
"/v1",
json=LinkRequest.model_construct(url=url, cmd="request.get").model_dump(),
)
if response.status_code == HTTPStatus.REQUEST_TIMEOUT:
pytest.skip("Skipping JSON API test - timed out (upstream issue)")
assert response.status_code == HTTPStatus.OK
solution = response.json()["solution"]
assert solution["user_agent"]
assert '"ip"' in solution["response"]
def test_health_check():
"""
Tests the health check endpoint.