duck3-create Claude Opus 4.6 commited on
Commit
aefaf06
·
1 Parent(s): 4123369

Add CONSENT cookie to Worker for YouTube bypass

Browse files

- YouTube returns consent page without cookies
- Add CONSENT and SOCS cookies to skip consent screen
- Forward Accept-Language from original request

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. worker/index.js +10 -5
worker/index.js CHANGED
@@ -18,12 +18,17 @@ export default {
18
  }
19
 
20
  try {
 
 
 
 
 
 
 
 
21
  const response = await fetch(targetUrl, {
22
- headers: {
23
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
24
- 'Accept-Language': 'ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7',
25
- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
26
- },
27
  });
28
 
29
  const body = await response.arrayBuffer();
 
18
  }
19
 
20
  try {
21
+ // Build headers: start with original request headers, override key ones
22
+ const headers = new Headers();
23
+ headers.set('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36');
24
+ headers.set('Accept-Language', request.headers.get('Accept-Language') || 'ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7');
25
+ headers.set('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8');
26
+ // CONSENT cookie bypasses YouTube's consent screen
27
+ headers.set('Cookie', 'CONSENT=PENDING+987; SOCS=CAISHAgCEhJnd3NfMjAyNDAxMDEtMF9SQzIaAmVuIAEaBgiA0JCuBg');
28
+
29
  const response = await fetch(targetUrl, {
30
+ headers,
31
+ redirect: 'follow',
 
 
 
32
  });
33
 
34
  const body = await response.arrayBuffer();