From 46a3c68eb05c6156f981151e6e15a09ea4349c59 Mon Sep 17 00:00:00 2001 From: ThePhaseless Date: Tue, 11 Aug 2026 11:08:04 +0200 Subject: [PATCH] fix: disable Firefox JSON viewer so evaluate works on JSON APIs Firefox renders application/json documents in a built-in viewer whose own CSP () 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. --- src/utils.py | 6 ++++++ tests/main_test.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/utils.py b/src/utils.py index e34bca9..83f1470 100644 --- a/src/utils.py +++ b/src/utils.py @@ -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) diff --git a/tests/main_test.py b/tests/main_test.py index ced8a60..cc8a5dd 100644 --- a/tests/main_test.py +++ b/tests/main_test.py @@ -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.