From 652c2347826842e69c7cf41d3d127335b804a1be Mon Sep 17 00:00:00 2001 From: ThePhaseless Date: Fri, 14 Aug 2026 22:22:53 +0200 Subject: [PATCH] refactor: drop redundant navigator.userAgent evaluate page.goto() returns None only for about:blank or a same-URL-different-hash navigation, so page_request is always present for a real request and its headers always carry the UA. The evaluate call was therefore unreachable as a fallback and, once moved before navigation, silently became the primary source instead. Request headers are also the correct source: consumers replay them with the clearance cookies, so the UA the server saw is the one to report. This restores the ordering d3a828e established. Co-Authored-By: Claude Opus 5 --- src/endpoints.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/endpoints.py b/src/endpoints.py index 1982372..bfed590 100644 --- a/src/endpoints.py +++ b/src/endpoints.py @@ -60,12 +60,6 @@ async def read_item(request: LinkRequest, dep: BrowserDep) -> LinkResponse: timer = TimeoutTimer(duration=request.max_timeout) request.url = request.url.replace('"', "").strip() - try: - user_agent = await dep.page.evaluate("navigator.userAgent") - except Exception: - logger.warning("Could not determine User-Agent via page.evaluate") - user_agent = None - await setup_routes(request, dep) try: @@ -86,8 +80,9 @@ async def read_item(request: LinkRequest, dep: BrowserDep) -> LinkResponse: page_html=page_html, ) - if user_agent is None: - user_agent = page_request.request.headers.get("user-agent") if page_request else "" + user_agent = ( + page_request.request.headers.get("user-agent") if page_request else "" + ) return LinkResponse( message="Success",