Patch Fetch.requestPaused to return all the headers and don't miss cross-frame requests
Sites with cloudflare managed challenge can see the JA4 of that completion and compare it to later origin requests. We need the browser to issue the requests, and our HTTP/2 (or HTTP/3) daemon to be the actual HTTP/TLS client, then fulfill the responses so the page cannot tell the transport changed. JS env we can patch ourselves. Transport JA4 is the remaining trait.
Firefox (Camoufox + Playwright page.route("**/*")) already does this: we pause, proxy the site domain, challenges.cloudflare.com, and *.challenges.cloudflare.com, fulfill, page continues. We need the same on Cloak.
What we tried on Cloak (CDP Fetch) and what happened
Fetch.enable on the page only Does not pause Turnstile FO / PAT / CI. Those are issued inside the cross-site OOPIF. Live result: page loaded the cross-frame parent domain HTML with no captcha iframe (iframe=0) and no Fetch.requestPaused for the challenge hosts.
Host-scoped urlPatterns Same miss on Cloak. We had to use urlPattern: "*" just to get any pauses, then continue the rest. Firefox's **/* did not have this problem.
Fetch.enable on ChromiumFrame / get_frames() / nested frames Never armed the Turnstile OOPIF in time. We only saw about:blank / same-target frames. FO / PAT / CI still did not pause.
Target.setAutoAttach({ autoAttach, waitForDebuggerOnStart, flatten }) + Fetch.enable on the attached iframe session This is the only combo that actually paused FO / PAT / CI (src=flat:*, type=iframe). Without waitForDebuggerOnStart those requests race past attach. This is not a usable product API:
Page CDP drops the envelope sessionId; fulfill/continue must go to the child session or they fail. Fetch.requestPaused still omits Cookie (we have to restore __cf_bm from the jar or PAT goes out cookieless and CF sets cf_chl_rc_ni). Extra headers are incomplete unless we also merge Network.requestWillBeSentExtraInfo. Fetch.fulfillRequest of a real 403 challenge document does not run CF JS in Chrome (Firefox Playwright fulfill of 403 does). We had to lie status 200 and strip COEP/COOP/CORP/CSP so the checkbox even starts. After pauses existed, fulfill of the large PAT/CI URLs and 4-level hosts (e.g. brunhild.challenges.cloudflare.com) still broke on our side. Stock Chrome Fetch is page-scoped. Cloak still behaves that way. Attach is a racey workaround, not intercept.
What we need
A Cloak-supported intercept (patched Fetch.requestPaused or a dedicated API) that:
Pauses every request the page makes, including cross-site iframes / OOPIFs and .challenges.cloudflare.com, without setAutoAttach / per-target Fetch.enable. Delivers the full request: all headers the browser would send (Cookie, Referer, client hints, sec-fetch-, ...), plus method, URL, body. Lets us fulfill or continue so the renderer sees a normal response. The page should not observe that HTTP/TLS ran in our daemon. Same shape as Playwright route on Firefox. This is the usual browser for JS, our stack for HTTP pattern. For us it is specifically CF completion on the target site so JA4 of the challenge matches the later origin session.
Code to reproduce:
"""Proof: Cloak page-level Fetch.requestPaused is not a usable intercept.
Opens https://peet.ws/turnstile-test/managed.html (checkbox). Page Fetch.enable
pauses what it can, then continueRequest so the widget still runs.
Expected:
- Cookie / Referer / client-hints often absent on Fetch.requestPaused
- challenges.cloudflare.com FO/PAT/CI inside the Turnstile iframe often
never pause at all (cross-site OOPIF)
DISPLAY=:10 drivers/.venv/bin/python drivers/cloak_fetch_turnstile_headers_proof.py
"""
from __future__ import annotations
import os
import sys
import time
from urllib.parse import urlparse
from DrissionPage import ChromiumOptions, ChromiumPage
URL = "https://peet.ws/turnstile-test/managed.html"
CLOAK = os.environ.get("CLOAK_CHROME", "/opt/browsers/cloakbrowser/chrome")
NEED = ("cookie", "referer", "origin", "sec-ch-ua", "sec-fetch-site")
def short(url: str) -> str:
p = urlparse(url or "")
path = p.path or "/"
if len(path) > 60:
path = path[:57] + "..."
return f"{p.scheme or 'https'}://{p.netloc}{path}"
def main():
os.environ.setdefault("DISPLAY", ":10")
opts = ChromiumOptions()
opts.set_browser_path(CLOAK)
opts.auto_port()
opts.set_argument("--no-sandbox")
opts.set_argument("--disable-dev-shm-usage")
opts.set_argument("--disable-gpu")
page = ChromiumPage(opts)
seen = []
def on_paused(**params):
req = params.get("request") or {}
url = req.get("url") or ""
method = req.get("method") or ""
raw = req.get("headers") or {}
headers = {str(k).lower(): str(v) for k, v in raw.items()}
missing = [n for n in NEED if n not in headers]
row = {
"method": method,
"host": (urlparse(url).hostname or "").lower(),
"url": short(url),
"names": sorted(headers),
"missing": missing,
}
seen.append(row)
miss = ",".join(missing) if missing else "(none)"
print(f"PAUSE {method} {row['url']}", flush=True)
print(f" header names: {', '.join(row['names']) or '(empty)'}", flush=True)
print(f" missing needed: {miss}", flush=True)
try:
page.run_cdp("Fetch.continueRequest", requestId=params.get("requestId"))
except Exception as err:
print(f" continue failed: {err}", flush=True)
page.run_cdp("Fetch.enable", patterns=[{"urlPattern": "*"}])
page._driver.set_callback("Fetch.requestPaused", on_paused, immediate=True)
print(f"Fetch.enable * → {URL}", flush=True)
print("click the checkbox; Ctrl+C when done\n", flush=True)
page.get(URL)
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
pass
chal = [r for r in seen if "challenges.cloudflare.com" in r["host"]]
fo_pat = [
r
for r in chal
if "/fo/" in r["url"] or "/pat/" in r["url"] or "/ci/" in r["url"]
]
miss_cookie = [r for r in seen if "cookie" in r["missing"]]
print("\n--- proof ---", flush=True)
print(f"Fetch.requestPaused total: {len(seen)}", flush=True)
print(f"challenges.cloudflare.com pauses: {len(chal)}", flush=True)
print(f"FO/PAT/CI pauses (iframe handshake): {len(fo_pat)}", flush=True)
print(f"pauses missing Cookie: {len(miss_cookie)}/{len(seen)}", flush=True)
if not fo_pat:
print(
"FAIL: page Fetch never paused Turnstile FO/PAT/CI (OOPIF iframe).",
flush=True,
)
if miss_cookie:
print("FAIL: Fetch.requestPaused omitted Cookie on paused requests.", flush=True)
try:
page.quit()
except Exception:
pass
if __name__ == "__main__":
try:
main()
except Exception as err:
print(f"error: {err}", file=sys.stderr)
sys.exit(1)Fetch.requestPaused total: 6
challenges.cloudflare.com pauses: 3
FO/PAT/CI pauses (iframe handshake): 0
pauses missing Cookie: 6/6
FAIL: page Fetch never paused Turnstile FO/PAT/CI (OOPIF iframe).
FAIL: Fetch.requestPaused omitted Cookie on paused requests.Example of working firefox's code part of what needs to be done with extended Cloakbrowser's request interception API:
def _firefox_h2_route_handler(page, *, page_html, h2, payload=None, done=None):
def on_route(route):
req = route.request
url = req.url or ""
method = req.method or ""
action = intercept_action(method, url, h2_enabled=h2 is not None)
if action != ACTION_CONTINUE:
print(
f"cf_clearance: firefox intercept {action} {method} "
f"{_short_url(url)} nonce={getattr(h2, 'nonce', '')}",
file=sys.stderr,
flush=True,
)
try:
if action == ACTION_STUB_PARENT_URL:
if page_html is None:
route.continue_()
return
route.fulfill(
status=200,
content_type="text/html; charset=utf-8",
body=page_html,
)
return
if action == ACTION_STUB_POST:
cookies = page.context.cookies()
if clearance_ready(cookies, h2):
route.fulfill(
status=200,
content_type="text/html; charset=utf-8",
body=b"test",
)
st = try_emit_clearance(cookies, h2, payload, done)
_handle_emit(st, cookies)
return
route.abort("aborted")
return
if action == ACTION_PROXY and h2 is not None:
body = None
try:
body = req.post_data_buffer
except Exception:
post = req.post_data
if post is not None:
body = (
post.encode("utf-8")
if isinstance(post, str)
else bytes(post)
)
cookies = page.context.cookies()
result = h2.proxy_browser_http(
method=method,
url=url,
headers=req.headers,
body=body,
cookies=cookies,
)
fulfill = sidecar_result_to_playwright_fulfill(result)
_apply_playwright_set_cookie(page, url, fulfill["set_cookie"])
route.fulfill(
status=fulfill["status"],
headers=fulfill["headers"],
body=fulfill["body"],
)
if is_CF_post_req(method, url):
st = try_emit_clearance(cookies, h2, payload, done)
_handle_emit(st, cookies)
return
route.continue_()Source: CloakHQ/CloakBrowser