refactor: simplify CSP stripping handler

Drop error handling and conditional branches that duplicated the
pass-through path; rely on the goto timeout as before.
This commit is contained in:
ThePhaseless
2026-08-08 00:31:25 +02:00
parent 6d447a0d67
commit e2fd2e6d42
+6 -19
View File
@@ -73,12 +73,6 @@ async def read_item(request: LinkRequest, dep: BrowserDep) -> LinkResponse:
await dep.page.route("**/*", block_media_route)
# The Firefox engine evaluates JS via eval(), which pages whose CSP lacks
# 'unsafe-eval' block - every page.evaluate() then fails with "call to
# eval() blocked by CSP". Rewrite document responses without CSP headers
# so the user-agent read and captcha solver work on CSP-locked pages.
# Juggler only routes the first request of a redirect chain, so follow
# redirects inside the fetch and record the final URL ourselves.
final_url: str | None = None
async def strip_csp_route(route) -> None:
@@ -86,24 +80,17 @@ async def read_item(request: LinkRequest, dep: BrowserDep) -> LinkResponse:
if route.request.resource_type != "document":
await route.continue_()
return
try:
response = await route.fetch()
except Exception:
await route.continue_()
return
response = await route.fetch()
if route.request.frame == dep.page.main_frame:
final_url = response.url
if response.headers.get("content-security-policy") or response.headers.get(
"content-security-policy-report-only"
):
headers = {
await route.fulfill(
response=response,
headers={
key: value
for key, value in response.headers.items()
if key.lower() not in CSP_HEADERS
}
await route.fulfill(response=response, headers=headers)
else:
await route.fulfill(response=response)
},
)
await dep.page.route("**/*", strip_csp_route)