scrapfly-sdk 0.10.2 → 0.10.4
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.
- package/esm/batch.d.ts.map +1 -1
- package/esm/batch.js +4 -0
- package/esm/client.d.ts.map +1 -1
- package/esm/client.js +17 -8
- package/package.json +1 -1
- package/script/batch.d.ts.map +1 -1
- package/script/batch.js +4 -0
- package/script/client.d.ts.map +1 -1
- package/script/client.js +17 -8
- package/src/_dnt.shims.ts +64 -0
- package/src/batch.ts +272 -0
- package/src/browserconfig.ts +118 -0
- package/src/client.ts +1609 -0
- package/src/crawl.ts +251 -0
- package/src/crawlerconfig.ts +363 -0
- package/src/crawlerresult.ts +471 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/assert_path.ts +10 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/basename.ts +53 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/common.ts +26 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/constants.ts +49 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/dirname.ts +9 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/format.ts +25 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/from_file_url.ts +10 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/glob_to_reg_exp.ts +290 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/normalize.ts +9 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/normalize_string.ts +74 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/relative.ts +10 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/strip_trailing_separators.ts +25 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_common/to_file_url.ts +17 -0
- package/src/deps/jsr.io/@std/path/1.0.1/_os.ts +31 -0
- package/src/deps/jsr.io/@std/path/1.0.1/basename.ts +35 -0
- package/src/deps/jsr.io/@std/path/1.0.1/common.ts +35 -0
- package/src/deps/jsr.io/@std/path/1.0.1/constants.ts +18 -0
- package/src/deps/jsr.io/@std/path/1.0.1/dirname.ts +28 -0
- package/src/deps/jsr.io/@std/path/1.0.1/extname.ts +27 -0
- package/src/deps/jsr.io/@std/path/1.0.1/format.ts +30 -0
- package/src/deps/jsr.io/@std/path/1.0.1/from_file_url.ts +30 -0
- package/src/deps/jsr.io/@std/path/1.0.1/glob_to_regexp.ts +94 -0
- package/src/deps/jsr.io/@std/path/1.0.1/is_absolute.ts +30 -0
- package/src/deps/jsr.io/@std/path/1.0.1/is_glob.ts +49 -0
- package/src/deps/jsr.io/@std/path/1.0.1/join.ts +28 -0
- package/src/deps/jsr.io/@std/path/1.0.1/join_globs.ts +42 -0
- package/src/deps/jsr.io/@std/path/1.0.1/mod.ts +55 -0
- package/src/deps/jsr.io/@std/path/1.0.1/normalize.ts +31 -0
- package/src/deps/jsr.io/@std/path/1.0.1/normalize_glob.ts +45 -0
- package/src/deps/jsr.io/@std/path/1.0.1/parse.ts +44 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/_util.ts +10 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/basename.ts +39 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/constants.ts +15 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/dirname.ts +55 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/extname.ts +73 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/format.ts +31 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/from_file_url.ts +25 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/glob_to_regexp.ts +94 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/is_absolute.ts +25 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/join.ts +27 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/join_globs.ts +44 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/normalize.ts +41 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/normalize_glob.ts +42 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/parse.ts +121 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/relative.ts +103 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/resolve.ts +69 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/to_file_url.ts +32 -0
- package/src/deps/jsr.io/@std/path/1.0.1/posix/to_namespaced_path.ts +21 -0
- package/src/deps/jsr.io/@std/path/1.0.1/relative.ts +32 -0
- package/src/deps/jsr.io/@std/path/1.0.1/resolve.ts +32 -0
- package/src/deps/jsr.io/@std/path/1.0.1/to_file_url.ts +30 -0
- package/src/deps/jsr.io/@std/path/1.0.1/to_namespaced_path.ts +31 -0
- package/src/deps/jsr.io/@std/path/1.0.1/types.ts +40 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/_util.ts +28 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/basename.ts +48 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/constants.ts +15 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/dirname.ts +114 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/extname.ts +86 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/format.ts +31 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/from_file_url.ts +34 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/glob_to_regexp.ts +92 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/is_absolute.ts +40 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/join.ts +72 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/join_globs.ts +45 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/normalize.ts +132 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/normalize_glob.ts +42 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/parse.ts +184 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/relative.ts +128 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/resolve.ts +174 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/to_file_url.ts +38 -0
- package/src/deps/jsr.io/@std/path/1.0.1/windows/to_namespaced_path.ts +60 -0
- package/src/deps.ts +4 -0
- package/src/errors.ts +55 -0
- package/src/extractionconfig.ts +175 -0
- package/src/logger.ts +51 -0
- package/src/main.ts +61 -0
- package/src/monitoringconfig.ts +50 -0
- package/src/polyfill.ts +37 -0
- package/src/result.ts +338 -0
- package/src/scrapeconfig.ts +448 -0
- package/src/screenshotconfig.ts +204 -0
- package/src/types.ts +2 -0
- package/src/utils.ts +86 -0
- package/src/webhookserver.ts +66 -0
package/esm/batch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../src/batch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA0CH,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,UAAU,CAAC;CAClB;AAED;;;;;;GAMG;AACH,wBAAuB,cAAc,CAAC,QAAQ,EAAE,QAAQ,GAAG,cAAc,CAAC,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../src/batch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA0CH,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,UAAU,CAAC;CAClB;AAED;;;;;;GAMG;AACH,wBAAuB,cAAc,CAAC,QAAQ,EAAE,QAAQ,GAAG,cAAc,CAAC,SAAS,CAAC,CA4HnF;AAoBD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,SAAS,GAAG,CAAC,CAS9D;AAOD;;;;;;;;;;GAUG;AACH,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,SAAS,GAAG,QAAQ,CAiCxE"}
|
package/esm/batch.js
CHANGED
|
@@ -84,6 +84,10 @@ export async function* iterBatchParts(response) {
|
|
|
84
84
|
return false;
|
|
85
85
|
}
|
|
86
86
|
if (value && value.length > 0) {
|
|
87
|
+
// reader.read() returns Uint8Array<ArrayBufferLike> on newer Deno/TS
|
|
88
|
+
// lib types while dnt's Node target still sees Uint8Array as
|
|
89
|
+
// non-generic. Cast to the non-generic form so the same source
|
|
90
|
+
// type-checks on both targets.
|
|
87
91
|
buf = concat(buf, value);
|
|
88
92
|
return true;
|
|
89
93
|
}
|
package/esm/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,gBAAgB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE5I,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,KAAK,mBAAmB,EAAE,eAAe,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC5H,OAAO,EAEL,KAAK,6BAA6B,EAClC,KA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,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAgBtG;;OAEG;IACG,wBAAwB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAgBjF;;;OAGG;IACG,2BAA2B,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC;IAmCpH;;;OAGG;IACG,kCAAkC,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC;IAoB/H;;;OAGG;IACG,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,WAAW,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAkBxF;;OAEG;IACG,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAgBvE;;OAEG;IACG,oBAAoB,IAAI,OAAO,CAAC;QAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CAe1E"}
|
package/esm/client.js
CHANGED
|
@@ -704,17 +704,23 @@ export class ScrapflyClient {
|
|
|
704
704
|
* Turn scrapfly screenshot API response to ScreenshotResult or raise one of ScrapflyError
|
|
705
705
|
*/
|
|
706
706
|
async handleScreenshotResponse(response) {
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
707
|
+
// A Response body can only be consumed once. If the server returned
|
|
708
|
+
// JSON, parse it up front and reuse it on the error path — re-reading
|
|
709
|
+
// would yield "body stream already read" and mask the real error.
|
|
710
|
+
const isJson = response.headers.get('content-type') === 'application/json';
|
|
711
|
+
let jsonData = null;
|
|
712
|
+
if (isJson) {
|
|
713
|
+
jsonData = (await response.json());
|
|
714
|
+
if (jsonData.http_code == 401 || response.status == 401) {
|
|
715
|
+
throw new errors.BadApiKeyError(JSON.stringify(jsonData));
|
|
711
716
|
}
|
|
712
|
-
if ('error_id' in
|
|
713
|
-
throw new errors.ScreenshotApiError(JSON.stringify(
|
|
717
|
+
if ('error_id' in jsonData) {
|
|
718
|
+
throw new errors.ScreenshotApiError(JSON.stringify(jsonData));
|
|
714
719
|
}
|
|
715
720
|
}
|
|
716
721
|
if (!response.ok) {
|
|
717
|
-
|
|
722
|
+
const body = jsonData ?? (await response.text());
|
|
723
|
+
throw new errors.ScreenshotApiError(typeof body === 'string' ? body : JSON.stringify(body));
|
|
718
724
|
}
|
|
719
725
|
const data = await response.arrayBuffer();
|
|
720
726
|
const result = new ScreenshotResult(response, data);
|
|
@@ -750,6 +756,9 @@ export class ScrapflyClient {
|
|
|
750
756
|
* Turn scrapfly Extraction API response to ExtractionResult or raise one of ScrapflyError
|
|
751
757
|
*/
|
|
752
758
|
async handleExtractionResponse(response) {
|
|
759
|
+
// Body can only be consumed once — reuse the parsed JSON on the
|
|
760
|
+
// error path instead of re-reading, which would fail with
|
|
761
|
+
// "body stream already read".
|
|
753
762
|
const data = (await response.json());
|
|
754
763
|
if ('error_id' in data) {
|
|
755
764
|
if (data.http_code == 401 || response.status == 401) {
|
|
@@ -758,7 +767,7 @@ export class ScrapflyClient {
|
|
|
758
767
|
throw new errors.ExtractionApiError(JSON.stringify(data));
|
|
759
768
|
}
|
|
760
769
|
if (!response.ok) {
|
|
761
|
-
throw new errors.ApiHttpClientError(JSON.stringify(
|
|
770
|
+
throw new errors.ApiHttpClientError(JSON.stringify(data));
|
|
762
771
|
}
|
|
763
772
|
const result = new ExtractionResult({
|
|
764
773
|
data: data.data,
|
package/package.json
CHANGED
package/script/batch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../src/batch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA0CH,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,UAAU,CAAC;CAClB;AAED;;;;;;GAMG;AACH,wBAAuB,cAAc,CAAC,QAAQ,EAAE,QAAQ,GAAG,cAAc,CAAC,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../src/batch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA0CH,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,UAAU,CAAC;CAClB;AAED;;;;;;GAMG;AACH,wBAAuB,cAAc,CAAC,QAAQ,EAAE,QAAQ,GAAG,cAAc,CAAC,SAAS,CAAC,CA4HnF;AAoBD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,SAAS,GAAG,CAAC,CAS9D;AAOD;;;;;;;;;;GAUG;AACH,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,SAAS,GAAG,QAAQ,CAiCxE"}
|
package/script/batch.js
CHANGED
|
@@ -89,6 +89,10 @@ async function* iterBatchParts(response) {
|
|
|
89
89
|
return false;
|
|
90
90
|
}
|
|
91
91
|
if (value && value.length > 0) {
|
|
92
|
+
// reader.read() returns Uint8Array<ArrayBufferLike> on newer Deno/TS
|
|
93
|
+
// lib types while dnt's Node target still sees Uint8Array as
|
|
94
|
+
// non-generic. Cast to the non-generic form so the same source
|
|
95
|
+
// type-checks on both targets.
|
|
92
96
|
buf = concat(buf, value);
|
|
93
97
|
return true;
|
|
94
98
|
}
|
package/script/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1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CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC;IAoB/H;;;OAGG;IACG,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,WAAW,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAkBxF;;OAEG;IACG,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAgBvE;;OAEG;IACG,oBAAoB,IAAI,OAAO,CAAC;QAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CAe1E"}
|
package/script/client.js
CHANGED
|
@@ -730,17 +730,23 @@ class ScrapflyClient {
|
|
|
730
730
|
* Turn scrapfly screenshot API response to ScreenshotResult or raise one of ScrapflyError
|
|
731
731
|
*/
|
|
732
732
|
async handleScreenshotResponse(response) {
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
733
|
+
// A Response body can only be consumed once. If the server returned
|
|
734
|
+
// JSON, parse it up front and reuse it on the error path — re-reading
|
|
735
|
+
// would yield "body stream already read" and mask the real error.
|
|
736
|
+
const isJson = response.headers.get('content-type') === 'application/json';
|
|
737
|
+
let jsonData = null;
|
|
738
|
+
if (isJson) {
|
|
739
|
+
jsonData = (await response.json());
|
|
740
|
+
if (jsonData.http_code == 401 || response.status == 401) {
|
|
741
|
+
throw new errors.BadApiKeyError(JSON.stringify(jsonData));
|
|
737
742
|
}
|
|
738
|
-
if ('error_id' in
|
|
739
|
-
throw new errors.ScreenshotApiError(JSON.stringify(
|
|
743
|
+
if ('error_id' in jsonData) {
|
|
744
|
+
throw new errors.ScreenshotApiError(JSON.stringify(jsonData));
|
|
740
745
|
}
|
|
741
746
|
}
|
|
742
747
|
if (!response.ok) {
|
|
743
|
-
|
|
748
|
+
const body = jsonData ?? (await response.text());
|
|
749
|
+
throw new errors.ScreenshotApiError(typeof body === 'string' ? body : JSON.stringify(body));
|
|
744
750
|
}
|
|
745
751
|
const data = await response.arrayBuffer();
|
|
746
752
|
const result = new result_js_1.ScreenshotResult(response, data);
|
|
@@ -776,6 +782,9 @@ class ScrapflyClient {
|
|
|
776
782
|
* Turn scrapfly Extraction API response to ExtractionResult or raise one of ScrapflyError
|
|
777
783
|
*/
|
|
778
784
|
async handleExtractionResponse(response) {
|
|
785
|
+
// Body can only be consumed once — reuse the parsed JSON on the
|
|
786
|
+
// error path instead of re-reading, which would fail with
|
|
787
|
+
// "body stream already read".
|
|
779
788
|
const data = (await response.json());
|
|
780
789
|
if ('error_id' in data) {
|
|
781
790
|
if (data.http_code == 401 || response.status == 401) {
|
|
@@ -784,7 +793,7 @@ class ScrapflyClient {
|
|
|
784
793
|
throw new errors.ExtractionApiError(JSON.stringify(data));
|
|
785
794
|
}
|
|
786
795
|
if (!response.ok) {
|
|
787
|
-
throw new errors.ApiHttpClientError(JSON.stringify(
|
|
796
|
+
throw new errors.ApiHttpClientError(JSON.stringify(data));
|
|
788
797
|
}
|
|
789
798
|
const result = new result_js_1.ExtractionResult({
|
|
790
799
|
data: data.data,
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Deno } from "@deno/shim-deno";
|
|
2
|
+
export { Deno } from "@deno/shim-deno";
|
|
3
|
+
|
|
4
|
+
const dntGlobals = {
|
|
5
|
+
Deno,
|
|
6
|
+
};
|
|
7
|
+
export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
|
8
|
+
|
|
9
|
+
function createMergeProxy<T extends object, U extends object>(
|
|
10
|
+
baseObj: T,
|
|
11
|
+
extObj: U,
|
|
12
|
+
): Omit<T, keyof U> & U {
|
|
13
|
+
return new Proxy(baseObj, {
|
|
14
|
+
get(_target, prop, _receiver) {
|
|
15
|
+
if (prop in extObj) {
|
|
16
|
+
return (extObj as any)[prop];
|
|
17
|
+
} else {
|
|
18
|
+
return (baseObj as any)[prop];
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
set(_target, prop, value) {
|
|
22
|
+
if (prop in extObj) {
|
|
23
|
+
delete (extObj as any)[prop];
|
|
24
|
+
}
|
|
25
|
+
(baseObj as any)[prop] = value;
|
|
26
|
+
return true;
|
|
27
|
+
},
|
|
28
|
+
deleteProperty(_target, prop) {
|
|
29
|
+
let success = false;
|
|
30
|
+
if (prop in extObj) {
|
|
31
|
+
delete (extObj as any)[prop];
|
|
32
|
+
success = true;
|
|
33
|
+
}
|
|
34
|
+
if (prop in baseObj) {
|
|
35
|
+
delete (baseObj as any)[prop];
|
|
36
|
+
success = true;
|
|
37
|
+
}
|
|
38
|
+
return success;
|
|
39
|
+
},
|
|
40
|
+
ownKeys(_target) {
|
|
41
|
+
const baseKeys = Reflect.ownKeys(baseObj);
|
|
42
|
+
const extKeys = Reflect.ownKeys(extObj);
|
|
43
|
+
const extKeysSet = new Set(extKeys);
|
|
44
|
+
return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
|
|
45
|
+
},
|
|
46
|
+
defineProperty(_target, prop, desc) {
|
|
47
|
+
if (prop in extObj) {
|
|
48
|
+
delete (extObj as any)[prop];
|
|
49
|
+
}
|
|
50
|
+
Reflect.defineProperty(baseObj, prop, desc);
|
|
51
|
+
return true;
|
|
52
|
+
},
|
|
53
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
54
|
+
if (prop in extObj) {
|
|
55
|
+
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
|
56
|
+
} else {
|
|
57
|
+
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
has(_target, prop) {
|
|
61
|
+
return prop in extObj || prop in baseObj;
|
|
62
|
+
},
|
|
63
|
+
}) as any;
|
|
64
|
+
}
|
package/src/batch.ts
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streaming multipart/mixed parser for POST /scrape/batch.
|
|
3
|
+
*
|
|
4
|
+
* The API emits one part per scrape as each completes. This module
|
|
5
|
+
* reads the response body as a ReadableStream and yields
|
|
6
|
+
* `(headers, body)` pairs as each part lands.
|
|
7
|
+
*
|
|
8
|
+
* No external dependencies — uses Web Streams (native in Node 18+
|
|
9
|
+
* and all modern browsers).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const CR = 0x0d;
|
|
13
|
+
const LF = 0x0a;
|
|
14
|
+
const CRLF = new Uint8Array([CR, LF]);
|
|
15
|
+
const DOUBLE_CRLF = new Uint8Array([CR, LF, CR, LF]);
|
|
16
|
+
|
|
17
|
+
function indexOf(buf: Uint8Array, needle: Uint8Array, start = 0): number {
|
|
18
|
+
if (needle.length === 0) return start;
|
|
19
|
+
const last = buf.length - needle.length;
|
|
20
|
+
outer: for (let i = start; i <= last; i++) {
|
|
21
|
+
for (let j = 0; j < needle.length; j++) {
|
|
22
|
+
if (buf[i + j] !== needle[j]) continue outer;
|
|
23
|
+
}
|
|
24
|
+
return i;
|
|
25
|
+
}
|
|
26
|
+
return -1;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function concat(a: Uint8Array, b: Uint8Array): Uint8Array {
|
|
30
|
+
const out = new Uint8Array(a.length + b.length);
|
|
31
|
+
out.set(a, 0);
|
|
32
|
+
out.set(b, a.length);
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function parseContentType(value: string): { mime: string; params: Record<string, string> } {
|
|
37
|
+
const semi = value.indexOf(';');
|
|
38
|
+
if (semi < 0) return { mime: value.trim().toLowerCase(), params: {} };
|
|
39
|
+
const mime = value.slice(0, semi).trim().toLowerCase();
|
|
40
|
+
const params: Record<string, string> = {};
|
|
41
|
+
for (const piece of value.slice(semi + 1).split(';')) {
|
|
42
|
+
const eq = piece.indexOf('=');
|
|
43
|
+
if (eq < 0) continue;
|
|
44
|
+
const k = piece.slice(0, eq).trim().toLowerCase();
|
|
45
|
+
let v = piece.slice(eq + 1).trim();
|
|
46
|
+
if (v.startsWith('"') && v.endsWith('"')) v = v.slice(1, -1);
|
|
47
|
+
params[k] = v;
|
|
48
|
+
}
|
|
49
|
+
return { mime, params };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface BatchPart {
|
|
53
|
+
headers: Record<string, string>;
|
|
54
|
+
body: Uint8Array;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Async iterator over multipart/mixed parts from a fetch Response.
|
|
59
|
+
*
|
|
60
|
+
* Yields one `BatchPart` per multipart section as it arrives on the
|
|
61
|
+
* wire. Throws if the response Content-Type is not multipart/mixed
|
|
62
|
+
* or the boundary is missing.
|
|
63
|
+
*/
|
|
64
|
+
export async function* iterBatchParts(response: Response): AsyncGenerator<BatchPart> {
|
|
65
|
+
const ct = response.headers.get('content-type') ?? '';
|
|
66
|
+
const { mime, params } = parseContentType(ct);
|
|
67
|
+
if (mime !== 'multipart/mixed') {
|
|
68
|
+
throw new Error(`scrapeBatch: expected Content-Type multipart/mixed, got ${JSON.stringify(ct)}`);
|
|
69
|
+
}
|
|
70
|
+
const boundaryStr = params['boundary'];
|
|
71
|
+
if (!boundaryStr) {
|
|
72
|
+
throw new Error(`scrapeBatch: Content-Type multipart/mixed is missing boundary parameter: ${JSON.stringify(ct)}`);
|
|
73
|
+
}
|
|
74
|
+
if (!response.body) {
|
|
75
|
+
throw new Error('scrapeBatch: response has no body stream');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const boundary = new TextEncoder().encode('--' + boundaryStr);
|
|
79
|
+
const nextBoundarySep = new TextEncoder().encode('\r\n--' + boundaryStr);
|
|
80
|
+
const reader = response.body.getReader();
|
|
81
|
+
|
|
82
|
+
let buf = new Uint8Array(0);
|
|
83
|
+
let eof = false;
|
|
84
|
+
let pastPrefix = false;
|
|
85
|
+
|
|
86
|
+
const pump = async (): Promise<boolean> => {
|
|
87
|
+
if (eof) return false;
|
|
88
|
+
const { done, value } = await reader.read();
|
|
89
|
+
if (done) {
|
|
90
|
+
eof = true;
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
if (value && value.length > 0) {
|
|
94
|
+
// reader.read() returns Uint8Array<ArrayBufferLike> on newer Deno/TS
|
|
95
|
+
// lib types while dnt's Node target still sees Uint8Array as
|
|
96
|
+
// non-generic. Cast to the non-generic form so the same source
|
|
97
|
+
// type-checks on both targets.
|
|
98
|
+
buf = concat(buf, value as unknown as Uint8Array);
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
return false;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const readUntil = async (needle: Uint8Array): Promise<Uint8Array> => {
|
|
105
|
+
while (true) {
|
|
106
|
+
const idx = indexOf(buf, needle);
|
|
107
|
+
if (idx !== -1) {
|
|
108
|
+
const out = buf.subarray(0, idx);
|
|
109
|
+
buf = buf.subarray(idx + needle.length);
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
if (eof) {
|
|
113
|
+
const out = buf;
|
|
114
|
+
buf = new Uint8Array(0);
|
|
115
|
+
return out;
|
|
116
|
+
}
|
|
117
|
+
if (!(await pump())) {
|
|
118
|
+
const out = buf;
|
|
119
|
+
buf = new Uint8Array(0);
|
|
120
|
+
return out;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const readExact = async (n: number): Promise<Uint8Array> => {
|
|
126
|
+
while (buf.length < n && !eof) {
|
|
127
|
+
await pump();
|
|
128
|
+
}
|
|
129
|
+
const out = buf.subarray(0, Math.min(n, buf.length));
|
|
130
|
+
buf = buf.subarray(out.length);
|
|
131
|
+
return out;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
while (true) {
|
|
135
|
+
if (!pastPrefix) {
|
|
136
|
+
await readUntil(boundary);
|
|
137
|
+
pastPrefix = true;
|
|
138
|
+
}
|
|
139
|
+
// After each --boundary, expect CRLF (more parts) or `--` (terminator).
|
|
140
|
+
// RFC 2046 mandates CRLF; any server deviating from that is broken —
|
|
141
|
+
// return cleanly rather than try to guess.
|
|
142
|
+
const suffix = await readExact(2);
|
|
143
|
+
if (suffix.length < 2) return;
|
|
144
|
+
if (suffix[0] === 0x2d && suffix[1] === 0x2d) {
|
|
145
|
+
// Final boundary marker "--"
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (!(suffix[0] === CR && suffix[1] === LF)) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Read headers up to blank line (CRLF CRLF).
|
|
153
|
+
const headerBlock = await readUntil(DOUBLE_CRLF);
|
|
154
|
+
const headers: Record<string, string> = {};
|
|
155
|
+
for (const lineBytes of splitByCRLF(headerBlock)) {
|
|
156
|
+
const line = new TextDecoder('utf-8').decode(lineBytes);
|
|
157
|
+
const colon = line.indexOf(':');
|
|
158
|
+
if (colon <= 0) continue;
|
|
159
|
+
headers[line.slice(0, colon).trim().toLowerCase()] = line.slice(colon + 1).trim();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Body framing: prefer Content-Length (server always emits it).
|
|
163
|
+
// When Content-Length is known, yield the part IMMEDIATELY after
|
|
164
|
+
// reading the body bytes — don't wait for the next boundary
|
|
165
|
+
// separator to arrive. Otherwise the caller is blocked until
|
|
166
|
+
// part N+1 starts streaming, which defeats the whole point of
|
|
167
|
+
// per-part streaming (especially when scrape N+1 is a slow one).
|
|
168
|
+
let body: Uint8Array;
|
|
169
|
+
const cl = headers['content-length'];
|
|
170
|
+
let readSeparatorAfterYield = false;
|
|
171
|
+
if (cl && /^\d+$/.test(cl)) {
|
|
172
|
+
body = await readExact(parseInt(cl, 10));
|
|
173
|
+
readSeparatorAfterYield = true;
|
|
174
|
+
} else {
|
|
175
|
+
body = await readUntil(nextBoundarySep);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
yield { headers, body };
|
|
179
|
+
|
|
180
|
+
// With Content-Length framing, the "\r\n--<boundary>" separator
|
|
181
|
+
// follows the body but is not part of it. Consume it now — any
|
|
182
|
+
// blocking that happens here blocks the NEXT iteration, not this
|
|
183
|
+
// part's delivery.
|
|
184
|
+
if (readSeparatorAfterYield) {
|
|
185
|
+
await readUntil(nextBoundarySep);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function splitByCRLF(buf: Uint8Array): Uint8Array[] {
|
|
191
|
+
const out: Uint8Array[] = [];
|
|
192
|
+
let start = 0;
|
|
193
|
+
for (let i = 0; i < buf.length - 1; i++) {
|
|
194
|
+
if (buf[i] === CR && buf[i + 1] === LF) {
|
|
195
|
+
out.push(buf.subarray(start, i));
|
|
196
|
+
start = i + 2;
|
|
197
|
+
i++;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (start < buf.length) out.push(buf.subarray(start));
|
|
201
|
+
return out;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// msgpack decoder. The module is npm:@msgpack/msgpack — dnt rewrites
|
|
205
|
+
// this to a regular npm import in the published package.
|
|
206
|
+
import { decode as msgpackDecode } from '@msgpack/msgpack';
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Decode a part body according to its content-type header. Supports
|
|
210
|
+
* both application/json (default) and application/msgpack.
|
|
211
|
+
*/
|
|
212
|
+
export function decodePartBody<T = unknown>(part: BatchPart): T {
|
|
213
|
+
const ct = part.headers['content-type'] ?? 'application/json';
|
|
214
|
+
if (ct.startsWith('application/json')) {
|
|
215
|
+
return JSON.parse(new TextDecoder('utf-8').decode(part.body)) as T;
|
|
216
|
+
}
|
|
217
|
+
if (ct.startsWith('application/msgpack') || ct.startsWith('application/x-msgpack')) {
|
|
218
|
+
return msgpackDecode(part.body) as T;
|
|
219
|
+
}
|
|
220
|
+
throw new Error(`scrapeBatch: unsupported part Content-Type: ${ct}`);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Header prefix used by the server to forward upstream response
|
|
224
|
+
// headers on proxified batch parts (avoids collision with the
|
|
225
|
+
// multipart envelope's own headers).
|
|
226
|
+
const UPSTREAM_PREFIX = 'x-scrapfly-upstream-';
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Synthesize a native fetch `Response` from a proxified batch part.
|
|
230
|
+
* The part body is the raw upstream bytes and the part carries:
|
|
231
|
+
* * `Content-Type` — the upstream's content-type
|
|
232
|
+
* * `X-Scrapfly-Scrape-Status` — the upstream's HTTP status
|
|
233
|
+
* * `X-Scrapfly-Upstream-<Name>` — upstream response headers
|
|
234
|
+
* * `X-Scrapfly-Log-Uuid`, `X-Scrapfly-Content-Format` — scrapfly metadata
|
|
235
|
+
*
|
|
236
|
+
* We return a Response with those values restored so the caller
|
|
237
|
+
* gets the same shape as a single proxified scrape.
|
|
238
|
+
*/
|
|
239
|
+
export function buildProxifiedResponseFromPart(part: BatchPart): Response {
|
|
240
|
+
const statusHeader = part.headers['x-scrapfly-scrape-status'];
|
|
241
|
+
const status = statusHeader ? parseInt(statusHeader, 10) || 200 : 200;
|
|
242
|
+
|
|
243
|
+
const headers = new Headers();
|
|
244
|
+
for (const [key, value] of Object.entries(part.headers)) {
|
|
245
|
+
const lower = key.toLowerCase();
|
|
246
|
+
if (lower === 'content-type') {
|
|
247
|
+
headers.set('Content-Type', value);
|
|
248
|
+
} else if (lower.startsWith(UPSTREAM_PREFIX)) {
|
|
249
|
+
headers.set(key.slice(UPSTREAM_PREFIX.length), value);
|
|
250
|
+
} else if (lower.startsWith('x-scrapfly-')) {
|
|
251
|
+
headers.set(key, value);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Normalize X-Scrapfly-Log-Uuid → X-Scrapfly-Log for parity with
|
|
256
|
+
// the single-scrape proxified response headers.
|
|
257
|
+
if (!headers.has('X-Scrapfly-Log') && headers.has('X-Scrapfly-Log-Uuid')) {
|
|
258
|
+
headers.set('X-Scrapfly-Log', headers.get('X-Scrapfly-Log-Uuid') ?? '');
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Wrap the Uint8Array in an ArrayBuffer so fetch Response accepts
|
|
262
|
+
// it (Node's fetch is picky about BodyInit).
|
|
263
|
+
// Copy into a fresh ArrayBuffer to avoid SharedArrayBuffer edge
|
|
264
|
+
// cases when the underlying bytes came from a larger buffer.
|
|
265
|
+
const bodyBuffer = new Uint8Array(part.body.length);
|
|
266
|
+
bodyBuffer.set(part.body);
|
|
267
|
+
|
|
268
|
+
return new Response(bodyBuffer, {
|
|
269
|
+
status,
|
|
270
|
+
headers,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
export enum ProxyPool {
|
|
2
|
+
DATACENTER = 'datacenter',
|
|
3
|
+
RESIDENTIAL = 'residential',
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export enum OperatingSystem {
|
|
7
|
+
LINUX = 'linux',
|
|
8
|
+
WINDOWS = 'windows',
|
|
9
|
+
MACOS = 'macos',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type BrowserConfigOptions = {
|
|
13
|
+
proxy_pool?: ProxyPool | string;
|
|
14
|
+
os?: OperatingSystem | string;
|
|
15
|
+
session?: string;
|
|
16
|
+
country?: string;
|
|
17
|
+
auto_close?: boolean;
|
|
18
|
+
timeout?: number;
|
|
19
|
+
debug?: boolean;
|
|
20
|
+
extensions?: string[];
|
|
21
|
+
block_images?: boolean;
|
|
22
|
+
block_styles?: boolean;
|
|
23
|
+
block_fonts?: boolean;
|
|
24
|
+
block_media?: boolean;
|
|
25
|
+
screenshot?: boolean;
|
|
26
|
+
resolution?: string;
|
|
27
|
+
target_url?: string;
|
|
28
|
+
cache?: boolean;
|
|
29
|
+
blacklist?: boolean;
|
|
30
|
+
unblock?: boolean;
|
|
31
|
+
unblock_timeout?: number;
|
|
32
|
+
browser_brand?: string;
|
|
33
|
+
enable_mcp?: boolean;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export class BrowserConfig {
|
|
37
|
+
proxy_pool?: string;
|
|
38
|
+
os?: string;
|
|
39
|
+
session?: string;
|
|
40
|
+
country?: string;
|
|
41
|
+
auto_close?: boolean;
|
|
42
|
+
timeout?: number;
|
|
43
|
+
debug?: boolean;
|
|
44
|
+
extensions?: string[];
|
|
45
|
+
block_images?: boolean;
|
|
46
|
+
block_styles?: boolean;
|
|
47
|
+
block_fonts?: boolean;
|
|
48
|
+
block_media?: boolean;
|
|
49
|
+
screenshot?: boolean;
|
|
50
|
+
resolution?: string;
|
|
51
|
+
target_url?: string;
|
|
52
|
+
cache?: boolean;
|
|
53
|
+
blacklist?: boolean;
|
|
54
|
+
unblock?: boolean;
|
|
55
|
+
unblock_timeout?: number;
|
|
56
|
+
browser_brand?: string;
|
|
57
|
+
enable_mcp?: boolean;
|
|
58
|
+
|
|
59
|
+
constructor(options: BrowserConfigOptions = {}) {
|
|
60
|
+
if (options.timeout !== undefined && options.timeout > 1800) {
|
|
61
|
+
throw new Error('timeout cannot exceed 1800 seconds (30 minutes)');
|
|
62
|
+
}
|
|
63
|
+
this.proxy_pool = options.proxy_pool;
|
|
64
|
+
this.os = options.os;
|
|
65
|
+
this.session = options.session;
|
|
66
|
+
this.country = options.country;
|
|
67
|
+
this.auto_close = options.auto_close;
|
|
68
|
+
this.timeout = options.timeout;
|
|
69
|
+
this.debug = options.debug;
|
|
70
|
+
this.extensions = options.extensions;
|
|
71
|
+
this.block_images = options.block_images;
|
|
72
|
+
this.block_styles = options.block_styles;
|
|
73
|
+
this.block_fonts = options.block_fonts;
|
|
74
|
+
this.block_media = options.block_media;
|
|
75
|
+
this.screenshot = options.screenshot;
|
|
76
|
+
this.resolution = options.resolution;
|
|
77
|
+
this.target_url = options.target_url;
|
|
78
|
+
this.cache = options.cache;
|
|
79
|
+
this.blacklist = options.blacklist;
|
|
80
|
+
this.unblock = options.unblock;
|
|
81
|
+
this.unblock_timeout = options.unblock_timeout;
|
|
82
|
+
this.browser_brand = options.browser_brand;
|
|
83
|
+
this.enable_mcp = options.enable_mcp;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Generate the WebSocket URL for a Cloud Browser session.
|
|
88
|
+
*/
|
|
89
|
+
websocketUrl(apiKey: string, host?: string): string {
|
|
90
|
+
const params = new URLSearchParams();
|
|
91
|
+
params.set('api_key', apiKey);
|
|
92
|
+
|
|
93
|
+
if (this.proxy_pool !== undefined) params.set('proxy_pool', this.proxy_pool);
|
|
94
|
+
if (this.os !== undefined) params.set('os', this.os);
|
|
95
|
+
if (this.session !== undefined) params.set('session', this.session);
|
|
96
|
+
if (this.country !== undefined) params.set('country', this.country);
|
|
97
|
+
if (this.auto_close !== undefined) params.set('auto_close', String(this.auto_close));
|
|
98
|
+
if (this.timeout !== undefined) params.set('timeout', String(this.timeout));
|
|
99
|
+
if (this.debug !== undefined) params.set('debug', String(this.debug));
|
|
100
|
+
if (this.extensions && this.extensions.length > 0) params.set('extensions', this.extensions.join(','));
|
|
101
|
+
if (this.block_images !== undefined) params.set('block_images', String(this.block_images));
|
|
102
|
+
if (this.block_styles !== undefined) params.set('block_styles', String(this.block_styles));
|
|
103
|
+
if (this.block_fonts !== undefined) params.set('block_fonts', String(this.block_fonts));
|
|
104
|
+
if (this.block_media !== undefined) params.set('block_media', String(this.block_media));
|
|
105
|
+
if (this.screenshot !== undefined) params.set('screenshot', String(this.screenshot));
|
|
106
|
+
if (this.resolution !== undefined) params.set('resolution', this.resolution);
|
|
107
|
+
if (this.target_url !== undefined) params.set('target_url', this.target_url);
|
|
108
|
+
if (this.cache !== undefined) params.set('cache', String(this.cache));
|
|
109
|
+
if (this.blacklist !== undefined) params.set('blacklist', String(this.blacklist));
|
|
110
|
+
if (this.unblock !== undefined) params.set('unblock', String(this.unblock));
|
|
111
|
+
if (this.unblock_timeout !== undefined) params.set('unblock_timeout', String(this.unblock_timeout));
|
|
112
|
+
if (this.browser_brand !== undefined) params.set('browser_brand', this.browser_brand);
|
|
113
|
+
if (this.enable_mcp !== undefined) params.set('enable_mcp', String(this.enable_mcp));
|
|
114
|
+
|
|
115
|
+
const baseHost = host || 'wss://browser.scrapfly.io';
|
|
116
|
+
return `${baseHost}?${params.toString()}`;
|
|
117
|
+
}
|
|
118
|
+
}
|