react-native-consumet 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/android/src/main/java/com/consumet/HttpRequestModule.kt +88 -33
  2. package/android/src/main/java/com/consumet/WebViewTask.kt +18 -3
  3. package/ios/Consumet.mm +172 -72
  4. package/lib/commonjs/NativeConsumet.ts +11 -5
  5. package/lib/commonjs/extension-registry.json +6 -6
  6. package/lib/commonjs/extension-registry.json.sig +1 -1
  7. package/lib/commonjs/extractors/kwik.js +28 -29
  8. package/lib/commonjs/extractors/kwik.js.map +1 -1
  9. package/lib/commonjs/providers/anime/animepahe/create-animepahe.js +12 -13
  10. package/lib/commonjs/providers/anime/animepahe/create-animepahe.js.map +1 -1
  11. package/lib/module/NativeConsumet.ts +11 -5
  12. package/lib/module/extension-registry.json +6 -6
  13. package/lib/module/extension-registry.json.sig +1 -1
  14. package/lib/module/extractors/kwik.js +28 -29
  15. package/lib/module/extractors/kwik.js.map +1 -1
  16. package/lib/module/providers/anime/animepahe/create-animepahe.js +12 -13
  17. package/lib/module/providers/anime/animepahe/create-animepahe.js.map +1 -1
  18. package/lib/typescript/commonjs/src/NativeConsumet.d.ts +11 -5
  19. package/lib/typescript/commonjs/src/NativeConsumet.d.ts.map +1 -1
  20. package/lib/typescript/commonjs/src/extractors/kwik.d.ts +1 -1
  21. package/lib/typescript/commonjs/src/extractors/kwik.d.ts.map +1 -1
  22. package/lib/typescript/commonjs/src/providers/anime/animepahe/create-animepahe.d.ts.map +1 -1
  23. package/lib/typescript/module/src/NativeConsumet.d.ts +11 -5
  24. package/lib/typescript/module/src/NativeConsumet.d.ts.map +1 -1
  25. package/lib/typescript/module/src/extractors/kwik.d.ts +1 -1
  26. package/lib/typescript/module/src/extractors/kwik.d.ts.map +1 -1
  27. package/lib/typescript/module/src/providers/anime/animepahe/create-animepahe.d.ts.map +1 -1
  28. package/package.json +1 -1
  29. package/src/NativeConsumet.ts +11 -5
  30. package/src/extension-registry.json +6 -6
  31. package/src/extension-registry.json.sig +1 -1
  32. package/src/extractors/kwik.ts +30 -43
  33. package/src/providers/anime/animepahe/create-animepahe.ts +15 -14
@@ -7,6 +7,7 @@ import android.util.Log
7
7
  import android.webkit.ConsoleMessage
8
8
  import android.webkit.CookieManager
9
9
  import android.webkit.WebChromeClient
10
+ import android.webkit.WebView
10
11
  import com.facebook.react.bridge.Promise
11
12
  import com.facebook.react.bridge.ReadableMap
12
13
  import com.facebook.react.bridge.WritableNativeMap
@@ -65,12 +66,29 @@ class HttpRequestModule(private val context: Context) {
65
66
  private val handler = Handler(Looper.getMainLooper())
66
67
 
67
68
  companion object {
68
- private const val DEFAULT_USER_AGENT =
69
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"
70
-
71
69
  // Time for scripts on the page to settle after it finishes loading (same as iOS).
72
70
  private const val CAPTURE_DELAY_MS = 1500L
73
71
 
72
+ // How often a page that isn't ready yet is checked again.
73
+ private const val POLL_MS = 1000L
74
+
75
+ // "challenge" on a Cloudflare challenge page ("Just a moment..."), which turns into the real
76
+ // page once its script has run; otherwise "ready" once the document has loaded, else
77
+ // "loading" (same as iOS).
78
+ private val PAGE_STATE_SCRIPT = """
79
+ (function() {
80
+ try {
81
+ if (window._cf_chl_opt ||
82
+ document.getElementById('challenge-form') ||
83
+ document.getElementById('challenge-running') ||
84
+ document.title === 'Just a moment...') return 'challenge';
85
+ return document.readyState === 'complete' ? 'ready' : 'loading';
86
+ } catch(e) {
87
+ return 'ready';
88
+ }
89
+ })();
90
+ """.trimIndent()
91
+
74
92
  private val HTML_SCRIPT = """
75
93
  (function() {
76
94
  try {
@@ -138,22 +156,22 @@ class HttpRequestModule(private val context: Context) {
138
156
  Log.d(TAG, "makeGetRequestWithWebView called with url: $url")
139
157
  val requestHeaders = WebViewHeaders.from(headers)
140
158
  handler.post {
141
- val task = WebViewTask(context, promise, requestHeaders.userAgent ?: DEFAULT_USER_AGENT)
159
+ // Without a User-Agent header the WebView keeps its own: Cloudflare fails a challenge
160
+ // whose user agent claims another browser than the WebView's client hints report.
161
+ val task = WebViewTask(context, promise, requestHeaders.userAgent)
142
162
  logConsoleMessages(task)
143
163
  task.onPageFinished = { view, loadedUrl ->
144
164
  Log.d(TAG, "onPageFinished for url: $loadedUrl")
145
- handler.postDelayed({
146
- if (!task.isSettled) {
147
- view.evaluateJavascript(HTML_SCRIPT) { htmlResponse: String? ->
148
- val result = WritableNativeMap()
149
- result.putString("url", loadedUrl)
150
- result.putString("html", decodeJsString(htmlResponse) ?: "")
151
- result.putString("cookies", CookieManager.getInstance().getCookie(loadedUrl) ?: "")
152
- result.putString("status", "success")
153
- task.resolve(result)
154
- }
165
+ captureUnlessChallenge(task, view) {
166
+ view.evaluateJavascript(HTML_SCRIPT) { htmlResponse: String? ->
167
+ val result = WritableNativeMap()
168
+ result.putString("url", loadedUrl)
169
+ result.putString("html", decodeJsString(htmlResponse) ?: "")
170
+ result.putString("cookies", CookieManager.getInstance().getCookie(loadedUrl) ?: "")
171
+ result.putString("status", "success")
172
+ task.resolve(result)
155
173
  }
156
- }, CAPTURE_DELAY_MS)
174
+ }
157
175
  }
158
176
  seedCookies(url, requestHeaders.cookie)
159
177
  task.start { webView ->
@@ -182,29 +200,29 @@ class HttpRequestModule(private val context: Context) {
182
200
  Log.d(TAG, "makePostRequestWithWebView called with url: $url")
183
201
  val requestHeaders = WebViewHeaders.from(headers)
184
202
  handler.post {
185
- val task = WebViewTask(context, promise, requestHeaders.userAgent ?: DEFAULT_USER_AGENT)
203
+ // Without a User-Agent header the WebView keeps its own: Cloudflare fails a challenge
204
+ // whose user agent claims another browser than the WebView's client hints report.
205
+ val task = WebViewTask(context, promise, requestHeaders.userAgent)
186
206
  logConsoleMessages(task)
187
207
  task.onPageFinished = { view, loadedUrl ->
188
208
  Log.d(TAG, "onPageFinished for url: $loadedUrl")
189
- handler.postDelayed({
190
- if (!task.isSettled) {
191
- view.evaluateJavascript(POST_RESPONSE_SCRIPT) { responseJson: String? ->
192
- // Like iOS, an unreadable capture gives an empty text/html response.
193
- val json = try {
194
- JSONObject(decodeJsString(responseJson) ?: "{}")
195
- } catch (e: Exception) {
196
- JSONObject()
197
- }
198
- val result = WritableNativeMap()
199
- result.putString("url", loadedUrl)
200
- result.putString("response", json.optString("content", ""))
201
- result.putString("cookies", CookieManager.getInstance().getCookie(loadedUrl) ?: "")
202
- result.putString("status", "success")
203
- result.putString("contentType", json.optString("contentType", "text/html"))
204
- task.resolve(result)
209
+ captureUnlessChallenge(task, view) {
210
+ view.evaluateJavascript(POST_RESPONSE_SCRIPT) { responseJson: String? ->
211
+ // Like iOS, an unreadable capture gives an empty text/html response.
212
+ val json = try {
213
+ JSONObject(decodeJsString(responseJson) ?: "{}")
214
+ } catch (e: Exception) {
215
+ JSONObject()
205
216
  }
217
+ val result = WritableNativeMap()
218
+ result.putString("url", loadedUrl)
219
+ result.putString("response", json.optString("content", ""))
220
+ result.putString("cookies", CookieManager.getInstance().getCookie(loadedUrl) ?: "")
221
+ result.putString("status", "success")
222
+ result.putString("contentType", json.optString("contentType", "text/html"))
223
+ task.resolve(result)
206
224
  }
207
- }, CAPTURE_DELAY_MS)
225
+ }
208
226
  }
209
227
  seedCookies(url, requestHeaders.cookie)
210
228
  Log.d(TAG, "Making POST request to: $url with body length: ${body.length}")
@@ -212,6 +230,43 @@ class HttpRequestModule(private val context: Context) {
212
230
  }
213
231
  }
214
232
 
233
+ /**
234
+ * Runs [capture] [CAPTURE_DELAY_MS] after the page finished loading, unless the page is a
235
+ * Cloudflare challenge: then the page is checked every [POLL_MS] until the challenge has turned
236
+ * into a loaded page, which is captured [CAPTURE_DELAY_MS] later, or the task times out.
237
+ * Polling the page, not waiting for navigation events, can't miss a reload that finished
238
+ * while a check was running.
239
+ */
240
+ private fun captureUnlessChallenge(task: WebViewTask, view: WebView, capture: () -> Unit) {
241
+ handler.postDelayed({ captureWhenReady(task, view, false, capture) }, CAPTURE_DELAY_MS)
242
+ }
243
+
244
+ private fun captureWhenReady(
245
+ task: WebViewTask,
246
+ view: WebView,
247
+ afterChallenge: Boolean,
248
+ capture: () -> Unit,
249
+ ) {
250
+ if (task.isSettled) return
251
+ view.evaluateJavascript(PAGE_STATE_SCRIPT) { result: String? ->
252
+ if (task.isSettled) return@evaluateJavascript
253
+ val state = decodeJsString(result)
254
+ if (state == "challenge" || state == "loading") {
255
+ if (state == "challenge" && !afterChallenge) {
256
+ Log.d(TAG, "Cloudflare challenge page; waiting for the page it turns into")
257
+ }
258
+ task.keepOpen()
259
+ val sawChallenge = afterChallenge || state == "challenge"
260
+ handler.postDelayed({ captureWhenReady(task, view, sawChallenge, capture) }, POLL_MS)
261
+ } else if (afterChallenge) {
262
+ // The page the challenge turned into gets the same time to settle as a first page.
263
+ handler.postDelayed({ if (!task.isSettled) capture() }, CAPTURE_DELAY_MS)
264
+ } else {
265
+ capture()
266
+ }
267
+ }
268
+ }
269
+
215
270
  /** Stores the pairs of a Cookie header for [url] before the WebView loads it. */
216
271
  private fun seedCookies(url: String, cookieHeader: String?) {
217
272
  if (cookieHeader.isNullOrEmpty()) return
@@ -3,6 +3,7 @@ package com.consumet
3
3
  import android.content.Context
4
4
  import android.os.Handler
5
5
  import android.os.Looper
6
+ import android.os.SystemClock
6
7
  import android.util.Log
7
8
  import android.webkit.CookieManager
8
9
  import android.webkit.WebResourceError
@@ -18,10 +19,12 @@ import com.facebook.react.bridge.Promise
18
19
  *
19
20
  * The promise settles exactly once:
20
21
  * - [onPageFinished] runs once, when the main document first finishes loading. Errors after
21
- * that are ignored and the callback settles the promise with [resolve] or [reject].
22
+ * that are ignored and the callback settles the promise with [resolve] or [reject], or calls
23
+ * [keepOpen] while it polls the page (a challenge page that turns into the real page once
24
+ * solved).
22
25
  * - A main-frame load error rejects with [WEBVIEW_ERROR]. Failed sub-resources (images, scripts,
23
26
  * iframes) are ignored, as WKWebView ignores them.
24
- * - No finished page within [TIMEOUT_MS] rejects with [TIMEOUT].
27
+ * - No settled promise within [TIMEOUT_MS] of [start] rejects with [TIMEOUT].
25
28
  */
26
29
  internal class WebViewTask(
27
30
  context: Context,
@@ -38,6 +41,7 @@ internal class WebViewTask(
38
41
  private val handler = Handler(Looper.getMainLooper())
39
42
  private val timeout = Runnable { reject(TIMEOUT, "WebView request timed out") }
40
43
  private var pageFinished = false
44
+ private var startedAt = 0L
41
45
 
42
46
  var isSettled = false
43
47
  private set
@@ -82,10 +86,21 @@ internal class WebViewTask(
82
86
  reject(WEBVIEW_ERROR, "WebView error: ${error.description}")
83
87
  }
84
88
  }
85
- handler.postDelayed(timeout, TIMEOUT_MS)
89
+ startedAt = SystemClock.uptimeMillis()
90
+ handler.postAtTime(timeout, startedAt + TIMEOUT_MS)
86
91
  load(webView)
87
92
  }
88
93
 
94
+ /**
95
+ * Keeps the task open after the page finished loading, for a caller that polls the page, until
96
+ * it settles or the [TIMEOUT_MS] deadline from [start] passes.
97
+ */
98
+ fun keepOpen() {
99
+ if (isSettled) return
100
+ handler.removeCallbacks(timeout)
101
+ handler.postAtTime(timeout, startedAt + TIMEOUT_MS)
102
+ }
103
+
89
104
  fun resolve(value: Any?) = settle { promise.resolve(value) }
90
105
 
91
106
  fun reject(code: String, message: String) = settle { promise.reject(code, message) }
package/ios/Consumet.mm CHANGED
@@ -3,10 +3,20 @@
3
3
  #import <JavaScriptCore/JavaScriptCore.h>
4
4
  #import <WebKit/WebKit.h>
5
5
 
6
- static NSString *const kDefaultUA =
7
- @"Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) "
8
- @"AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 "
9
- @"Safari/604.1";
6
+ // Without a User-Agent header a WebView keeps WKWebView's own user agent, with
7
+ // the tokens Mobile Safari adds for this iOS version, so it matches the engine:
8
+ // Cloudflare fails a challenge whose user agent claims another browser version
9
+ // (as on Android, where the WebView keeps its own).
10
+ static NSString *RCConsumetSafariApplicationName(void) {
11
+ NSArray<NSString *> *parts =
12
+ [UIDevice.currentDevice.systemVersion componentsSeparatedByString:@"."];
13
+ NSString *version =
14
+ parts.count > 1
15
+ ? [NSString stringWithFormat:@"%@.%@", parts[0], parts[1]]
16
+ : parts.firstObject;
17
+ return [NSString
18
+ stringWithFormat:@"Version/%@ Mobile/15E148 Safari/604.1", version];
19
+ }
10
20
 
11
21
  // Rejection codes shared with Android (see the contract in src/NativeConsumet.ts).
12
22
  static NSString *const kWebViewErrorCode = @"WEBVIEW_ERROR";
@@ -112,6 +122,10 @@ static void RCConsumetReadCookies(
112
122
  - (void)loadRequest:(NSURLRequest *)request
113
123
  userAgent:(nullable NSString *)ua
114
124
  cookieHeader:(nullable NSString *)cookieHeader;
125
+ /// Keeps the task open after the navigation finished, for a caller that polls
126
+ /// the page (a challenge page that turns into the real page once solved), until
127
+ /// it is cleaned up or the 30 s deadline from loadRequest passes.
128
+ - (void)keepOpen;
115
129
  - (void)cleanup;
116
130
  @end
117
131
 
@@ -119,7 +133,9 @@ static void RCConsumetReadCookies(
119
133
  WKWebView *_webView;
120
134
  UIWindow *_offscreenWindow;
121
135
  NSTimer *_timer;
136
+ NSDate *_startedAt;
122
137
  BOOL _done;
138
+ BOOL _keptOpen;
123
139
  }
124
140
 
125
141
  - (void)loadRequest:(NSURLRequest *)request
@@ -130,10 +146,12 @@ static void RCConsumetReadCookies(
130
146
 
131
147
  WKWebViewConfiguration *cfg = [WKWebViewConfiguration new];
132
148
  cfg.websiteDataStore = RCConsumetDataStore();
149
+ cfg.applicationNameForUserAgent = RCConsumetSafariApplicationName();
133
150
 
134
151
  _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)
135
152
  configuration:cfg];
136
- _webView.customUserAgent = ua.length ? ua : kDefaultUA;
153
+ if (ua.length)
154
+ _webView.customUserAgent = ua;
137
155
  _webView.navigationDelegate = self;
138
156
 
139
157
  // Attach to a tiny off-screen window so WKWebView loads resources properly.
@@ -142,6 +160,7 @@ static void RCConsumetReadCookies(
142
160
  _offscreenWindow.hidden = NO;
143
161
  [_offscreenWindow addSubview:_webView];
144
162
 
163
+ _startedAt = [NSDate date];
145
164
  _timer = [NSTimer scheduledTimerWithTimeInterval:30
146
165
  target:self
147
166
  selector:@selector(_didTimeout)
@@ -197,10 +216,25 @@ static void RCConsumetReadCookies(
197
216
  return cookies;
198
217
  }
199
218
 
219
+ - (void)keepOpen {
220
+ if (!_webView || _keptOpen)
221
+ return;
222
+ _keptOpen = YES;
223
+ [_timer invalidate];
224
+ NSTimeInterval elapsed = [[NSDate date] timeIntervalSinceDate:_startedAt];
225
+ _timer = [NSTimer scheduledTimerWithTimeInterval:MAX(30 - elapsed, 0)
226
+ target:self
227
+ selector:@selector(_didTimeout)
228
+ userInfo:nil
229
+ repeats:NO];
230
+ }
231
+
200
232
  - (void)_didTimeout {
201
- if (_done)
233
+ // A task kept open has finished its navigation (_done) but still times out.
234
+ if (_done && !_keptOpen)
202
235
  return;
203
236
  _done = YES;
237
+ _keptOpen = NO;
204
238
  if (self.onError)
205
239
  self.onError(kTimeoutCode, @"WebView request timed out");
206
240
  [self cleanup];
@@ -264,6 +298,77 @@ static void RCConsumetReadCookies(
264
298
 
265
299
  #pragma mark - Consumet Module
266
300
 
301
+ // "challenge" on a Cloudflare challenge page ("Just a moment..."), which turns
302
+ // into the real page once its script has run; otherwise "ready" once the
303
+ // document has loaded, else "loading" (as on Android).
304
+ static NSString *const kPageStateScript =
305
+ @"(function(){try{if(window._cf_chl_opt||"
306
+ @"document.getElementById('challenge-form')||"
307
+ @"document.getElementById('challenge-running')||"
308
+ @"document.title==='Just a moment...')return 'challenge';"
309
+ @"return document.readyState==='complete'?'ready':'loading';"
310
+ @"}catch(e){return 'ready';}})()";
311
+
312
+ /// Checks the page every second until a challenge has turned into a loaded
313
+ /// page, then runs capture 1.5 s later (or at once when there was none).
314
+ /// Polling the page, not waiting for navigation events, can't miss a reload
315
+ /// that finished while a check was running.
316
+ static void RCConsumetCaptureWhenReady(RCConsumetWebTask *task,
317
+ WKWebView *webView,
318
+ BOOL afterChallenge,
319
+ dispatch_block_t capture) {
320
+ __weak RCConsumetWebTask *wt = task;
321
+ __weak WKWebView *wv = webView;
322
+ [webView evaluateJavaScript:kPageStateScript
323
+ completionHandler:^(id result, NSError *error) {
324
+ if (!wv)
325
+ return;
326
+ BOOL challenge = [result isEqual:@"challenge"];
327
+ if (challenge || [result isEqual:@"loading"]) {
328
+ [wt keepOpen];
329
+ dispatch_after(
330
+ dispatch_time(DISPATCH_TIME_NOW, (int64_t)NSEC_PER_SEC),
331
+ dispatch_get_main_queue(), ^{
332
+ WKWebView *view = wv;
333
+ if (view)
334
+ RCConsumetCaptureWhenReady(wt, view,
335
+ afterChallenge || challenge,
336
+ capture);
337
+ });
338
+ } else if (afterChallenge) {
339
+ // The page the challenge turned into gets the same time to
340
+ // settle as a first page.
341
+ dispatch_after(
342
+ dispatch_time(DISPATCH_TIME_NOW,
343
+ (int64_t)(1.5 * NSEC_PER_SEC)),
344
+ dispatch_get_main_queue(), ^{
345
+ if (wv)
346
+ capture();
347
+ });
348
+ } else {
349
+ capture();
350
+ }
351
+ }];
352
+ }
353
+
354
+ /// Runs capture 1.5 s after a navigation finished (so scripts on the page can
355
+ /// settle), unless the page is a Cloudflare challenge: then capture waits for
356
+ /// the page the challenge turns into, and the task times out as usual if it
357
+ /// never does.
358
+ static void RCConsumetCaptureUnlessChallenge(RCConsumetWebTask *task,
359
+ WKWebView *webView,
360
+ dispatch_block_t capture) {
361
+ __weak RCConsumetWebTask *wt = task;
362
+ __weak WKWebView *wv = webView;
363
+ dispatch_after(
364
+ dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)),
365
+ dispatch_get_main_queue(), ^{
366
+ WKWebView *view = wv;
367
+ if (view)
368
+ RCConsumetCaptureWhenReady(wt, view, NO, capture);
369
+ });
370
+ }
371
+
267
372
  @implementation Consumet {
268
373
  NSMutableSet<RCConsumetWebTask *> *_tasks;
269
374
  }
@@ -304,7 +409,7 @@ RCT_EXPORT_MODULE()
304
409
  timeoutInterval:30];
305
410
  req.HTTPMethod = method;
306
411
 
307
- __block NSString *ua = kDefaultUA;
412
+ __block NSString *ua = nil;
308
413
  [headers enumerateKeysAndObjectsUsingBlock:^(NSString *k, NSString *v,
309
414
  BOOL *stop) {
310
415
  if ([k caseInsensitiveCompare:@"User-Agent"] == NSOrderedSame) {
@@ -464,7 +569,7 @@ RCT_EXPORT_MODULE()
464
569
  requestWithURL:[NSURL URLWithString:urlStr]
465
570
  cachePolicy:NSURLRequestReloadIgnoringCacheData
466
571
  timeoutInterval:30]
467
- userAgent:kDefaultUA
572
+ userAgent:nil
468
573
  cookieHeader:nil];
469
574
  });
470
575
  }
@@ -482,40 +587,37 @@ RCT_EXPORT_MODULE()
482
587
  __weak RCConsumetWebTask *wt = task;
483
588
 
484
589
  task.onFinish = ^(WKWebView *webView, NSString *loadedURL) {
485
- // Short delay so JS on the page has time to settle.
486
- dispatch_after(
487
- dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)),
488
- dispatch_get_main_queue(), ^{
489
- [webView
490
- evaluateJavaScript:@"(function(){try{return "
491
- @"document.documentElement.outerHTML;}catch("
492
- @"e){return '';}})()"
493
- completionHandler:^(id html, NSError *e) {
494
- NSString *htmlStr =
495
- [html isKindOfClass:[NSString class]] ? html : @"";
496
- NSString *finalURL = loadedURL.length ? loadedURL : urlStr;
497
- RCConsumetReadCookies(
498
- webView, finalURL,
499
- ^(NSArray<NSHTTPCookie *> *cookies,
500
- NSString *cookieStr) {
501
- resolve(@{
502
- @"url" : finalURL,
503
- @"html" : htmlStr,
504
- @"cookies" : cookieStr,
505
- @"status" : @"success"
506
- });
507
- [wt cleanup];
508
- [ws _removeTask:wt];
509
- });
510
- }];
511
- });
590
+ RCConsumetCaptureUnlessChallenge(wt, webView, ^{
591
+ [webView
592
+ evaluateJavaScript:@"(function(){try{return "
593
+ @"document.documentElement.outerHTML;}catch("
594
+ @"e){return '';}})()"
595
+ completionHandler:^(id html, NSError *e) {
596
+ NSString *htmlStr =
597
+ [html isKindOfClass:[NSString class]] ? html : @"";
598
+ NSString *finalURL = loadedURL.length ? loadedURL : urlStr;
599
+ RCConsumetReadCookies(
600
+ webView, finalURL,
601
+ ^(NSArray<NSHTTPCookie *> *cookies,
602
+ NSString *cookieStr) {
603
+ resolve(@{
604
+ @"url" : finalURL,
605
+ @"html" : htmlStr,
606
+ @"cookies" : cookieStr,
607
+ @"status" : @"success"
608
+ });
609
+ [wt cleanup];
610
+ [ws _removeTask:wt];
611
+ });
612
+ }];
613
+ });
512
614
  };
513
615
  task.onError = ^(NSString *code, NSString *desc) {
514
616
  reject(code, desc, nil);
515
617
  [ws _removeTask:wt];
516
618
  };
517
619
 
518
- NSString *ua = kDefaultUA;
620
+ NSString *ua = nil;
519
621
  NSMutableURLRequest *req = [self _requestWithURL:urlStr
520
622
  method:@"GET"
521
623
  headers:headers
@@ -554,48 +656,46 @@ RCT_EXPORT_MODULE()
554
656
  @"})()";
555
657
 
556
658
  task.onFinish = ^(WKWebView *webView, NSString *loadedURL) {
557
- dispatch_after(
558
- dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)),
559
- dispatch_get_main_queue(), ^{
560
- [webView
561
- evaluateJavaScript:jsExtract
562
- completionHandler:^(id r, NSError *e) {
563
- NSString *finalURL = loadedURL.length ? loadedURL : urlStr;
564
- RCConsumetReadCookies(
565
- webView, finalURL,
566
- ^(NSArray<NSHTTPCookie *> *cookies,
567
- NSString *cookieStr) {
568
- NSString *jsonStr =
569
- [r isKindOfClass:[NSString class]] ? r : @"{}";
570
- id json = [NSJSONSerialization
571
- JSONObjectWithData:
572
- [jsonStr
573
- dataUsingEncoding:NSUTF8StringEncoding]
574
- options:0
575
- error:nil];
576
- NSDictionary *parsed =
577
- [json isKindOfClass:[NSDictionary class]] ? json
578
- : @{};
579
- resolve(@{
580
- @"url" : finalURL,
581
- @"response" : parsed[@"content"] ?: @"",
582
- @"cookies" : cookieStr,
583
- @"status" : @"success",
584
- @"contentType" : parsed[@"contentType"]
585
- ?: @"text/html"
586
- });
587
- [wt cleanup];
588
- [ws _removeTask:wt];
589
- });
590
- }];
591
- });
659
+ RCConsumetCaptureUnlessChallenge(wt, webView, ^{
660
+ [webView
661
+ evaluateJavaScript:jsExtract
662
+ completionHandler:^(id r, NSError *e) {
663
+ NSString *finalURL = loadedURL.length ? loadedURL : urlStr;
664
+ RCConsumetReadCookies(
665
+ webView, finalURL,
666
+ ^(NSArray<NSHTTPCookie *> *cookies,
667
+ NSString *cookieStr) {
668
+ NSString *jsonStr =
669
+ [r isKindOfClass:[NSString class]] ? r : @"{}";
670
+ id json = [NSJSONSerialization
671
+ JSONObjectWithData:
672
+ [jsonStr
673
+ dataUsingEncoding:NSUTF8StringEncoding]
674
+ options:0
675
+ error:nil];
676
+ NSDictionary *parsed =
677
+ [json isKindOfClass:[NSDictionary class]] ? json
678
+ : @{};
679
+ resolve(@{
680
+ @"url" : finalURL,
681
+ @"response" : parsed[@"content"] ?: @"",
682
+ @"cookies" : cookieStr,
683
+ @"status" : @"success",
684
+ @"contentType" : parsed[@"contentType"]
685
+ ?: @"text/html"
686
+ });
687
+ [wt cleanup];
688
+ [ws _removeTask:wt];
689
+ });
690
+ }];
691
+ });
592
692
  };
593
693
  task.onError = ^(NSString *code, NSString *desc) {
594
694
  reject(code, desc, nil);
595
695
  [ws _removeTask:wt];
596
696
  };
597
697
 
598
- NSString *ua = kDefaultUA;
698
+ NSString *ua = nil;
599
699
  NSMutableURLRequest *req = [self _requestWithURL:urlStr
600
700
  method:@"POST"
601
701
  headers:headers
@@ -11,7 +11,7 @@ import { TurboModuleRegistry } from 'react-native';
11
11
  * | code | methods | meaning |
12
12
  * | ----------------- | ------------------------------ | --------------------------------------------------------------- |
13
13
  * | `WEBVIEW_ERROR` | WebView requests (below) | The main document failed to load (DNS, TLS, connection). |
14
- * | `TIMEOUT` | WebView requests (below) | The main document did not finish loading within 30 s. |
14
+ * | `TIMEOUT` | WebView requests (below) | No page (past any Cloudflare challenge) finished within 30 s. |
15
15
  * | `COOKIE_ERROR` | getDdosGuardCookiesWithWebView | The page loaded but set no `__ddg2_` cookie. |
16
16
  * | `ERROR` | bypassDdosGuard | Invalid URL, or no DDoS-Guard cookie could be obtained. |
17
17
  * | `HTTP_ERROR` | makePostRequest | Invalid URL or transport failure. HTTP error statuses resolve. |
@@ -23,7 +23,10 @@ import { TurboModuleRegistry } from 'react-native';
23
23
  * makePostRequestWithWebView) load the URL in a hidden WebView:
24
24
  * - Only the main document decides the outcome. Failed sub-resources (images, scripts, iframes)
25
25
  * are ignored, and HTTP error statuses (403, 503, ...) still resolve with the page.
26
- * - The first finished page settles the request; later navigations and errors are ignored.
26
+ * - The first finished page settles the request; later navigations and errors are ignored. The
27
+ * exception is a Cloudflare challenge page ("Just a moment..."): makeGetRequestWithWebView and
28
+ * makePostRequestWithWebView wait for the page the challenge reloads into once its script has
29
+ * run, within the same 30 s.
27
30
  * - `cookies` (and the getDdosGuardCookiesWithWebView result) is a Cookie header string with the
28
31
  * cookies that apply to the loaded URL.
29
32
  * - Cookies carry over between calls. Android uses the app-wide CookieManager; iOS uses an
@@ -46,9 +49,12 @@ export interface Spec extends TurboModule {
46
49
  */
47
50
  getDdosGuardCookiesWithWebView(url: string): Promise<string>;
48
51
  /**
49
- * Loads `url` in a hidden WebView and resolves 1.5 s after the main document finishes loading,
50
- * with its `outerHTML`, the final URL and its cookies. User-Agent and Cookie headers are applied
51
- * to the WebView; other headers are sent with the request. `status` is always `'success'`:
52
+ * Loads `url` in a hidden WebView and resolves 1.5 s after the main document finishes loading
53
+ * (the page a Cloudflare challenge reloads into, when the first page is one), with its
54
+ * `outerHTML`, the final URL and its cookies. User-Agent and Cookie headers are applied
55
+ * to the WebView; other headers are sent with the request. Without a User-Agent header the
56
+ * WebView keeps the engine's own (on iOS with Mobile Safari's tokens), which Cloudflare checks
57
+ * against what the engine reports. `status` is always `'success'`:
52
58
  * failures and timeouts reject (`WEBVIEW_ERROR`, `TIMEOUT`).
53
59
  */
54
60
  makeGetRequestWithWebView(
@@ -15,10 +15,10 @@
15
15
  },
16
16
  {
17
17
  "name": "Kwik",
18
- "version": "1.2.4",
18
+ "version": "1.2.5",
19
19
  "minContextVersion": 1,
20
- "main": "https://raw.githubusercontent.com/uwumilabs/react-native-consumet/refs/heads/main/registry/extractors/kwik/1.2.4.js",
21
- "sha256": "625158a91f9272470f9c645621133074f11f99b292680920494e14bbe9005d4c",
20
+ "main": "https://raw.githubusercontent.com/uwumilabs/react-native-consumet/refs/heads/main/registry/extractors/kwik/1.2.5.js",
21
+ "sha256": "d4b4992d35d6e8f5e00143deaf61e0c54c5bd1f402a64f376e8550dd77dbb68a",
22
22
  "distFile": "dist/bundles/extractors/kwik.js"
23
23
  },
24
24
  {
@@ -75,14 +75,14 @@
75
75
  "id": "animepahe",
76
76
  "name": "AnimePahe",
77
77
  "description": "High-quality anime streaming from AnimePahe with multiple servers and subtitles",
78
- "version": "1.2.6",
78
+ "version": "1.2.7",
79
79
  "minContextVersion": 1,
80
80
  "author": {
81
81
  "name": "RNConsumet Team",
82
82
  "url": "https://github.com/uwumilabs"
83
83
  },
84
84
  "category": "anime",
85
- "main": "https://raw.githubusercontent.com/uwumilabs/react-native-consumet/refs/heads/main/registry/extensions/animepahe/1.2.6.js",
85
+ "main": "https://raw.githubusercontent.com/uwumilabs/react-native-consumet/refs/heads/main/registry/extensions/animepahe/1.2.7.js",
86
86
  "factoryName": "createAnimePahe",
87
87
  "baseUrl": "https://animepahe.pw",
88
88
  "logo": "https://animepahe.pw/web-app-manifest-512x512.png",
@@ -100,7 +100,7 @@
100
100
  "dubbed": true,
101
101
  "isSourceEmbed": true,
102
102
  "haveMultiServers": false,
103
- "sha256": "a2c83cc43c95f2224c599e805d9f5dfc9b89b3c36713c20c6ef063790f31013d",
103
+ "sha256": "63b4fbf8c7333984e518545171571d43cd983479c9b1f14b9c194beec5966811",
104
104
  "distFile": "dist/bundles/providers/anime/animepahe/create-animepahe.js"
105
105
  },
106
106
  {
@@ -1 +1 @@
1
- b25a904d511520ca9612989cdc2662038eb972b949e55ba10b9955c16908fd57080989558a1ce1ff58aa8243f032d9e7c7378acbd2696152fa03123e86f83309
1
+ fa54678c129da118d355e4e5c0d0077224807ca6deb394e653ddc067c65958d371b89425d58e09836631c4b1c2ca19ef1520b73ca9dc9170598c56b9b3c56b0e