Skip to content

Fix recaptcha errors by removing Request cloning in service worker - #26

Draft
sriail with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-recaptcha-fetch-error
Draft

Fix recaptcha errors by removing Request cloning in service worker#26
sriail with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-recaptcha-fetch-error

Conversation

Copilot AI commented Nov 17, 2025

Copy link
Copy Markdown
Contributor

Service worker was cloning Request objects with consumed ReadableStream bodies, causing TypeError: Failed to construct 'Request': The provided ReadableStream is disturbed and cascading failures in recaptcha/captcha loading.

Changes

  • Removed request cloning logic - Deleted enhanceCaptchaRequest() function and CAPTCHA domain checking that attempted to create new Request objects from consumed streams
  • Pass original events to proxy handlers - Both uv.fetch() and sj.fetch() now receive unmodified fetch events, allowing their built-in CAPTCHA handling to work correctly

Before

// Attempted to clone requests with consumed streams
function enhanceCaptchaRequest(request) {
    const headers = new Headers(request.headers);
    return new Request(request, {  // ❌ Fails if request.body was read
        headers: headers,
        credentials: "include"
    });
}

if (isCaptcha) {
    request = enhanceCaptchaRequest(event.request);
}
return await uv.fetch(event);  // Received modified request

After

// Simply route to handlers with original event
if (url.startsWith(location.origin + __uv$config.prefix)) {
    return await uv.fetch(event);  // Receives original event with intact streams
} else if (sj.route(event)) {
    return await sj.fetch(event);
}

Both Ultraviolet and Scramjet include CAPTCHA handling when given the original fetch event.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • telemetry.astro.build
    • Triggering command: node /home/REDACTED/work/Radius/Radius/node_modules/.bin/astro build (dns block)
    • Triggering command: node /home/REDACTED/work/Radius/Radius/node_modules/.bin/astro dev (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

when trying to load a recapta, the console dysplays this error scramjet.all.js:1 %cg -> g%c Creating SingletonBox
background-color: #f80;
color: #fff;
padding: 4px;
font-weight: bold;
font-family: monospace;
font-size: 0.9em;

print @ scramjet.all.js:1
scramjet.all.js:1 ERROR FROM SERVICE WORKER FETCH: Object
m @ scramjet.all.js:1
scramjet.all.js:1 TypeError: Failed to construct 'Request': The provided ReadableStream is disturbed
at S.fetch (scramjet.all.js:1:102867)
at d.m (scramjet.all.js:1:89992)
at async sw.js:1:1353
m @ scramjet.all.js:1
:8080//scramjet/https%3A%2F%2Fwww.google.com%2Fgen_204%3Fs%3Dweb%26t%3Daft%26atyp%3Dcsi%26ei%3DBPsaaf-dC-K05NoP9JWJqAI%26rt%3Dwsrt.612%2Chst.417%2Csct.479%2Cfrts.524%2Cfrvt.524%2Cprt.711%2Cafts.567%2Caft.567%26imn%3D11%26dtc%3D596%26stc%3D170%26ima%3D0%26imad%3D0%26imac%3D2%26wh%3D593%26nt%3Dnavigate%26dt%3Dcache%26ts%3D0%26nhp%3D%26opi%3D89978449:1 Failed to load resource: the server responded with a status of 500 ()
scramjet.all.js:1 ERROR FROM SERVICE WORKER FETCH: Object
m @ scramjet.all.js:1
scramjet.all.js:1 TypeError: Failed to construct 'Request': The provided ReadableStream is disturbed
at S.fetch (scramjet.all.js:1:102867)
at d.m (scramjet.all.js:1:89992)
at async sw.js:1:1353
m @ scramjet.all.js:1
scramjet.all.js:1 Uncaught ReferenceError: registration is not defined
:8080/
/scramjet/https%3A%2F%2Fogads-pa.clients6.google.com%2F%24rpc%2Fgoogle.internal.onegoogle.asyncdata.v1.AsyncDataService%2FGetAsyncData:1 Failed to load resource: the server responded with a status of 500 ()
2scramjet.all.js:1 CAUGHT ERROR RpcError(UNKNOWN): Rpc failed due to xhr error. uri: https://ogads-pa.clients6.google.com/$rpc/google.internal.onegoogle.asyncdata.v1.AsyncDataService/GetAsyncData, error code: 6, error: [500]
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 ERROR FROM SERVICE WORKER FETCH: Object
m @ scramjet.all.js:1
scramjet.all.js:1 TypeError: Failed to construct 'Request': The provided ReadableStream is disturbed
at S.fetch (scramjet.all.js:1:102867)
at d.m (scramjet.all.js:1:89992)
at async sw.js:1:1353
m @ scramjet.all.js:1
:8080/url?sa=t&source=web&rct=j&opi=89978449&url=https://www.google.com/recaptcha/api2/demo&ved=2ahUKEwj_r9KF__iQAxViGlkFHfRKAiUQFnoECAwQAQ:1 Failed to load resource: the server responded with a status of 404 (Not Found)
scramjet.all.js:1 CAUGHT ERROR TypeError: Failed to fetch
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 ERROR FROM SERVICE WORKER FETCH: Object
m @ scramjet.all.js:1
scramjet.all.js:1 TypeError: Failed to construct 'Request': The provided ReadableStream is disturbed
at S.fetch (scramjet.all.js:1:102867)
at d.m (scramjet.all.js:1:89992)
at async sw.js:1:1353
m @ scramjet.all.js:1
scramjet.all.js:1 g initializing scramjet client
scramjet.all.js:1 g -> g Creating SingletonBox
print @ scramjet.all.js:1
scramjet.all.js:1 g initializing scramjet client
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 CAUGHT ERROR Array(3)
t.$scramerr @ scramjet.all.js:1
scramjet.all.js:1 C...


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@codesandbox

codesandbox Bot commented Nov 17, 2025

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Co-authored-by: sriail <225764385+sriail@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix recaptcha fetch error in service worker Fix recaptcha errors by removing Request cloning in service worker Nov 17, 2025
Copilot AI requested a review from sriail November 17, 2025 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants