@@ -11,14 +11,18 @@ export async function handlePage(
11
11
input : CheerioActorInput ,
12
12
requestQueue : RequestQueue ,
13
13
state : ActorCheckDetailedOutput ,
14
- { request, $, body, response, enqueueLinks } : CheerioCheckerHandlePageInputs ,
14
+ { request, $, body, response, enqueueLinks, json } : CheerioCheckerHandlePageInputs ,
15
15
) {
16
16
/** @type {string | undefined } */
17
17
let htmlUrl ;
18
18
19
19
if ( input . saveSnapshot ) {
20
20
const key = `SNAPSHOT-${ Math . random ( ) . toString ( ) } ` ;
21
- await Actor . setValue ( `${ key } .html` , body , { contentType : 'text/html' } ) ;
21
+ if ( json ) {
22
+ await Actor . setValue ( key , json ) ;
23
+ } else {
24
+ await Actor . setValue ( `${ key } .html` , body , { contentType : 'text/html' } ) ;
25
+ }
22
26
htmlUrl = `https://api.apify.com/v2/key-value-stores/${ Actor . getEnv ( ) . defaultKeyValueStoreId } /records/${ key } .html?disableRedirect=true` ;
23
27
}
24
28
@@ -30,15 +34,18 @@ export async function handlePage(
30
34
state . statusCodes [ statusCode ! ] . push ( { url : request . url , htmlUrl } ) ;
31
35
32
36
const captchas : string [ ] = [ ] ;
33
- const testResult = testHtml ( $ ) ;
37
+ // We don't have $ for JSON responses nor we can recognize captchas from it
38
+ if ( $ ) {
39
+ const testResult = testHtml ( $ ) ;
34
40
35
- for ( const testResultEntry of Object . entries ( testResult ) ) {
36
- const wasFound = testResultEntry [ 1 ] ;
37
- const testCase = testResultEntry [ 0 ] as 'accessDenied' | 'distilCaptcha' | 'recaptcha' | 'hCaptcha' ;
38
- if ( wasFound ) {
39
- captchas . push ( testCase ) ;
41
+ for ( const testResultEntry of Object . entries ( testResult ) ) {
42
+ const wasFound = testResultEntry [ 1 ] ;
43
+ const testCase = testResultEntry [ 0 ] as 'accessDenied' | 'distilCaptcha' | 'recaptcha' | 'hCaptcha' ;
44
+ if ( wasFound ) {
45
+ captchas . push ( testCase ) ;
40
46
41
- state [ testCase ] . push ( { url : request . url , htmlUrl } ) ;
47
+ state [ testCase ] . push ( { url : request . url , htmlUrl } ) ;
48
+ }
42
49
}
43
50
}
44
51
@@ -59,7 +66,7 @@ export async function handlePage(
59
66
const info = await requestQueue . getInfo ( ) ;
60
67
61
68
// Only queue up more requests in the queue if we should (this should avoid excessive queue writes)
62
- if ( input . maxNumberOfPagesCheckedPerDomain > info ! . totalRequestCount ) {
69
+ if ( input . maxNumberOfPagesCheckedPerDomain > info ! . totalRequestCount && ! ! $ ) {
63
70
await enqueueLinks ( {
64
71
selector : input . linkSelector ,
65
72
pseudoUrls : input . pseudoUrls . map (
0 commit comments