scrapfly-sdk 0.11.1 → 0.12.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.
- package/README.md +72 -5
- package/esm/browserconfig.d.ts +57 -9
- package/esm/browserconfig.d.ts.map +1 -1
- package/esm/browserconfig.js +63 -5
- package/esm/browserdownloads.d.ts +70 -0
- package/esm/browserdownloads.d.ts.map +1 -0
- package/esm/browserdownloads.js +215 -0
- package/esm/client.d.ts +224 -8
- package/esm/client.d.ts.map +1 -1
- package/esm/client.js +646 -62
- package/esm/crawl.d.ts +83 -1
- package/esm/crawl.d.ts.map +1 -1
- package/esm/crawl.js +73 -0
- package/esm/crawlerconfig.d.ts +54 -3
- package/esm/crawlerconfig.d.ts.map +1 -1
- package/esm/crawlerconfig.js +96 -2
- package/esm/crawlerresult.d.ts +374 -2
- package/esm/crawlerresult.d.ts.map +1 -1
- package/esm/crawlerresult.js +367 -1
- package/esm/errors.d.ts +12 -0
- package/esm/errors.d.ts.map +1 -1
- package/esm/errors.js +11 -0
- package/esm/main.d.ts +12 -7
- package/esm/main.d.ts.map +1 -1
- package/esm/main.js +10 -5
- package/esm/monitoringconfig.d.ts +2 -2
- package/esm/result.d.ts +11 -1
- package/esm/result.d.ts.map +1 -1
- package/esm/result.js +14 -5
- package/esm/scrapeconfig.d.ts +65 -1
- package/esm/scrapeconfig.d.ts.map +1 -1
- package/esm/scrapeconfig.js +88 -4
- package/esm/screenshotconfig.d.ts +9 -1
- package/esm/screenshotconfig.d.ts.map +1 -1
- package/esm/screenshotconfig.js +12 -1
- package/esm/types.d.ts +128 -0
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js +22 -1
- package/esm/utils.d.ts.map +1 -1
- package/esm/utils.js +16 -2
- package/esm/webhookserver.d.ts +33 -15
- package/esm/webhookserver.d.ts.map +1 -1
- package/esm/webhookserver.js +197 -38
- package/package.json +1 -1
- package/script/browserconfig.d.ts +57 -9
- package/script/browserconfig.d.ts.map +1 -1
- package/script/browserconfig.js +63 -5
- package/script/browserdownloads.d.ts +70 -0
- package/script/browserdownloads.d.ts.map +1 -0
- package/script/browserdownloads.js +221 -0
- package/script/client.d.ts +224 -8
- package/script/client.d.ts.map +1 -1
- package/script/client.js +645 -61
- package/script/crawl.d.ts +83 -1
- package/script/crawl.d.ts.map +1 -1
- package/script/crawl.js +73 -0
- package/script/crawlerconfig.d.ts +54 -3
- package/script/crawlerconfig.d.ts.map +1 -1
- package/script/crawlerconfig.js +97 -3
- package/script/crawlerresult.d.ts +374 -2
- package/script/crawlerresult.d.ts.map +1 -1
- package/script/crawlerresult.js +374 -2
- package/script/errors.d.ts +12 -0
- package/script/errors.d.ts.map +1 -1
- package/script/errors.js +12 -1
- package/script/main.d.ts +12 -7
- package/script/main.d.ts.map +1 -1
- package/script/main.js +20 -4
- package/script/monitoringconfig.d.ts +2 -2
- package/script/result.d.ts +11 -1
- package/script/result.d.ts.map +1 -1
- package/script/result.js +14 -5
- package/script/scrapeconfig.d.ts +65 -1
- package/script/scrapeconfig.d.ts.map +1 -1
- package/script/scrapeconfig.js +88 -4
- package/script/screenshotconfig.d.ts +9 -1
- package/script/screenshotconfig.d.ts.map +1 -1
- package/script/screenshotconfig.js +12 -1
- package/script/types.d.ts +128 -0
- package/script/types.d.ts.map +1 -1
- package/script/types.js +23 -0
- package/script/utils.d.ts.map +1 -1
- package/script/utils.js +16 -2
- package/script/webhookserver.d.ts +33 -15
- package/script/webhookserver.d.ts.map +1 -1
- package/script/webhookserver.js +197 -38
- package/src/browserconfig.ts +74 -8
- package/src/browserdownloads.ts +266 -0
- package/src/client.ts +796 -65
- package/src/crawl.ts +106 -0
- package/src/crawlerconfig.ts +128 -5
- package/src/crawlerresult.ts +607 -3
- package/src/errors.ts +12 -0
- package/src/main.ts +55 -5
- package/src/monitoringconfig.ts +2 -2
- package/src/result.ts +17 -5
- package/src/scrapeconfig.ts +92 -3
- package/src/screenshotconfig.ts +14 -1
- package/src/types.ts +159 -1
- package/src/utils.ts +16 -2
- package/src/webhookserver.ts +235 -39
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
`npm install scrapfly-sdk`
|
|
4
4
|
`deno add jsr:@scrapfly/scrapfly-sdk`
|
|
5
|
-
`
|
|
5
|
+
`bunx jsr add @scrapfly/scrapfly-sdk`
|
|
6
6
|
|
|
7
7
|
Typescript/Javascript SDK for [Scrapfly.io](https://scrapfly.io/) web scraping API which allows to:
|
|
8
8
|
|
|
@@ -41,10 +41,8 @@ const apiResponse = await client.scrape(
|
|
|
41
41
|
render_js: true,
|
|
42
42
|
// set proxy country
|
|
43
43
|
country: 'us',
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
// set residential proxies
|
|
47
|
-
proxy_pool: 'public_residential_pool',
|
|
44
|
+
// proxy pool: basic, unblocker (anti-bot bypass), unblocker_ultra or auto
|
|
45
|
+
proxy_pool: ScrapeConfig.UNBLOCKER,
|
|
48
46
|
// etc.
|
|
49
47
|
}),
|
|
50
48
|
);
|
|
@@ -57,6 +55,75 @@ For more see [/examples](/examples/) directory.
|
|
|
57
55
|
For more on Scrapfly API see our [getting started documentation](https://scrapfly.io/docs/scrape-api/getting-started)
|
|
58
56
|
For Python see [Scrapfly Python SDK](https://github.com/scrapfly/python-scrapfly)
|
|
59
57
|
|
|
58
|
+
### Proxy pools
|
|
59
|
+
|
|
60
|
+
`proxy_pool` picks one of four proxy pools. The pool sets both the proxy
|
|
61
|
+
network and the anti-bot bypass (the Unblocker):
|
|
62
|
+
|
|
63
|
+
| Static | Value | What it runs |
|
|
64
|
+
|---|---|---|
|
|
65
|
+
| `ScrapeConfig.BASIC` | `'basic'` | datacenter proxies, Unblocker off |
|
|
66
|
+
| `ScrapeConfig.UNBLOCKER` | `'unblocker'` | residential proxies and the Unblocker |
|
|
67
|
+
| `ScrapeConfig.UNBLOCKER_ULTRA` | `'unblocker_ultra'` | residential proxies and the Unblocker, the only pool accepted by the targets and anti-bot protections that have a price of their own |
|
|
68
|
+
| `ScrapeConfig.AUTO` | `'auto'` | the API picks the pool before the request, from the target's profile: the Unblocker on datacenter proxies, or the pool the target needs; accepted on every target, the ones that require `unblocker_ultra` included, where their price is added; priced as the pool it runs on |
|
|
69
|
+
|
|
70
|
+
```javascript
|
|
71
|
+
const result = await client.scrape(
|
|
72
|
+
new ScrapeConfig({ url: 'https://web-scraping.dev/product/1', proxy_pool: ScrapeConfig.UNBLOCKER }),
|
|
73
|
+
);
|
|
74
|
+
new CrawlerConfig({ url: 'https://web-scraping.dev/', proxy_pool: ScrapeConfig.UNBLOCKER });
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
A request on `basic` or `unblocker` against a target or protection that has a
|
|
78
|
+
price of its own fails with `ERR::PROXY::UNBLOCKER_ULTRA_REQUIRED` (HTTP 422,
|
|
79
|
+
not billed); retry it with `ScrapeConfig.UNBLOCKER_ULTRA`. `basic` is billed at
|
|
80
|
+
the datacenter price and both Unblocker pools at the residential price;
|
|
81
|
+
`unblocker_ultra` adds the target's or protection's own price where it has one.
|
|
82
|
+
The SDK sends no default `proxy_pool`.
|
|
83
|
+
|
|
84
|
+
`ScreenshotConfig` takes the same four pools, at the same price on every pool;
|
|
85
|
+
any other value is ignored there. The Cloud Browser (`BrowserConfig`)
|
|
86
|
+
keeps its own pools: `datacenter`, `residential`, `tor` and `byop`.
|
|
87
|
+
|
|
88
|
+
### Deprecated: `unblocker` and `asp`
|
|
89
|
+
|
|
90
|
+
`unblocker` and its alias `asp`, in both `ScrapeConfig` and `CrawlerConfig`, are
|
|
91
|
+
deprecated: use `proxy_pool` (`ScrapeConfig.UNBLOCKER_ULTRA` for the Unblocker).
|
|
92
|
+
The [migration guide](https://scrapfly.io/new-pricing#legacy-spellings) covers
|
|
93
|
+
the requests written before the proxy pools, the pool names
|
|
94
|
+
`ScrapeConfig.PUBLIC_DATACENTER_POOL` and `ScrapeConfig.PUBLIC_RESIDENTIAL_POOL`
|
|
95
|
+
included.
|
|
96
|
+
|
|
97
|
+
```javascript
|
|
98
|
+
new ScrapeConfig({ url: 'https://web-scraping.dev/product/1', unblocker: true }); // deprecated
|
|
99
|
+
new ScrapeConfig({ url: 'https://web-scraping.dev/product/1', asp: true }); // same thing
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Both names address one value, so `config.unblocker` and `config.asp` always
|
|
103
|
+
read the same and either can be assigned after construction. When both are
|
|
104
|
+
supplied to the constructor, `asp` wins - but only when it was actually
|
|
105
|
+
supplied: `asp: undefined` is not a supplied value, so `{ ...opts, asp: opts.asp }`
|
|
106
|
+
spread-forwarding cannot silently veto an explicit `unblocker: true`.
|
|
107
|
+
|
|
108
|
+
The request still carries the parameter as `asp` on the wire, in the `/scrape`
|
|
109
|
+
query and in the `POST /crawl` body, and only when the feature is ON - both
|
|
110
|
+
"off" and "not supplied" drop the key, so the request is byte-identical to the
|
|
111
|
+
one the Python, Go and Rust SDKs build for the same intent.
|
|
112
|
+
|
|
113
|
+
The matching error class is `errors.ScrapflyUnblockerError`, the same class
|
|
114
|
+
object as `errors.ScrapflyAspError`, so either name works in a `catch`. The API
|
|
115
|
+
error classes (`ScrapflyError` and its subclasses) are exported under the
|
|
116
|
+
`errors` namespace, not at the package root; `BrowserDownloadError` and
|
|
117
|
+
`ScheduleAPIError` are root exports:
|
|
118
|
+
|
|
119
|
+
```javascript
|
|
120
|
+
import { errors } from 'scrapfly-sdk';
|
|
121
|
+
|
|
122
|
+
if (err instanceof errors.ScrapflyUnblockerError) {
|
|
123
|
+
// the unblocker could not get through the target's protection
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
60
127
|
## Debugging
|
|
61
128
|
|
|
62
129
|
To enable debug logs set Scrapfly's log level to `"DEBUG"`:
|
package/esm/browserconfig.d.ts
CHANGED
|
@@ -12,7 +12,13 @@ export declare enum OperatingSystem {
|
|
|
12
12
|
/** Emulate a Windows browser fingerprint. */
|
|
13
13
|
WINDOWS = "windows",
|
|
14
14
|
/** Emulate a macOS browser fingerprint. */
|
|
15
|
-
MACOS = "macos"
|
|
15
|
+
MACOS = "macos",
|
|
16
|
+
/** Emulate an Android phone browser fingerprint. */
|
|
17
|
+
ANDROID = "android",
|
|
18
|
+
/** Emulate an iPhone browser fingerprint. */
|
|
19
|
+
IPHONE = "iphone",
|
|
20
|
+
/** Emulate an iPad browser fingerprint. */
|
|
21
|
+
IPAD = "ipad"
|
|
16
22
|
}
|
|
17
23
|
/**
|
|
18
24
|
* User-facing options accepted by {@link BrowserConfig}. All fields are
|
|
@@ -28,6 +34,18 @@ export type BrowserConfigOptions = {
|
|
|
28
34
|
session?: string;
|
|
29
35
|
/** ISO country code for geo-targeting. */
|
|
30
36
|
country?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Browser UI language — the singular `navigator.language` base tag
|
|
39
|
+
* (e.g. "en"). When omitted, the server derives it from `country`.
|
|
40
|
+
*/
|
|
41
|
+
lang?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Ordered language preference list driving `navigator.languages` and the
|
|
44
|
+
* q-weighted `Accept-Language` header (e.g. ["fr-FR", "fr", "en-US"]).
|
|
45
|
+
* Pass a comma-separated string or an array; capped server-side at 3
|
|
46
|
+
* entries.
|
|
47
|
+
*/
|
|
48
|
+
languages?: string | string[];
|
|
31
49
|
/** Close the browser automatically when the connection drops. */
|
|
32
50
|
auto_close?: boolean;
|
|
33
51
|
/** Session timeout in seconds (max 1800 = 30 minutes). */
|
|
@@ -54,16 +72,24 @@ export type BrowserConfigOptions = {
|
|
|
54
72
|
cache?: boolean;
|
|
55
73
|
/** Apply Scrapfly's abuse blacklist. */
|
|
56
74
|
blacklist?: boolean;
|
|
57
|
-
/**
|
|
75
|
+
/**
|
|
76
|
+
* @deprecated The Cloud Browser WebSocket endpoint does not read this
|
|
77
|
+
* parameter; it is sent but has no effect. Use
|
|
78
|
+
* {@link ScrapflyClient.cloudBrowserUnblock} (the `/unblock` endpoint).
|
|
79
|
+
*/
|
|
58
80
|
unblock?: boolean;
|
|
59
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* @deprecated The Cloud Browser WebSocket endpoint does not read this
|
|
83
|
+
* parameter; it is sent but has no effect. Use
|
|
84
|
+
* {@link ScrapflyClient.cloudBrowserUnblock}, which takes its own timeouts.
|
|
85
|
+
*/
|
|
60
86
|
unblock_timeout?: number;
|
|
61
87
|
/** Browser brand to emulate (e.g. "chrome", "firefox"). */
|
|
62
88
|
browser_brand?: string;
|
|
63
89
|
/** Enable the MCP (Model Context Protocol) bridge. */
|
|
64
90
|
enable_mcp?: boolean;
|
|
65
91
|
/**
|
|
66
|
-
* Arm
|
|
92
|
+
* Arm the Cloud Browser's built-in captcha detector + solver on the first page attach.
|
|
67
93
|
* Turnstile, DataDome slider, reCAPTCHA, GeeTest, PerimeterX hold, and
|
|
68
94
|
* puzzle captchas are handled automatically — no extra CDP calls from the
|
|
69
95
|
* client. Billed per solve; failures cost nothing.
|
|
@@ -99,6 +125,12 @@ export type BrowserConfigOptions = {
|
|
|
99
125
|
* comma-separated string or an array of bare IPs / CIDRs.
|
|
100
126
|
*/
|
|
101
127
|
hitl_allowed_networks?: string | string[];
|
|
128
|
+
/**
|
|
129
|
+
* Return large downloaded files from `ScrapiumBrowser.getDownloads` as IO stream handles instead of
|
|
130
|
+
* inline base64: read them with `CloudBrowserDownloads`.
|
|
131
|
+
* See https://scrapfly.io/docs/cloud-browser-api/file-downloads#large-downloads
|
|
132
|
+
*/
|
|
133
|
+
downloads_stream?: boolean;
|
|
102
134
|
};
|
|
103
135
|
/**
|
|
104
136
|
* Configuration for a Scrapfly Cloud Browser session. Builds the
|
|
@@ -114,6 +146,10 @@ export declare class BrowserConfig {
|
|
|
114
146
|
session?: string;
|
|
115
147
|
/** See {@link BrowserConfigOptions.country}. */
|
|
116
148
|
country?: string;
|
|
149
|
+
/** See {@link BrowserConfigOptions.lang}. */
|
|
150
|
+
lang?: string;
|
|
151
|
+
/** See {@link BrowserConfigOptions.languages}. Normalized to a comma-separated string. */
|
|
152
|
+
languages?: string;
|
|
117
153
|
/** See {@link BrowserConfigOptions.auto_close}. */
|
|
118
154
|
auto_close?: boolean;
|
|
119
155
|
/** See {@link BrowserConfigOptions.timeout}. */
|
|
@@ -140,9 +176,9 @@ export declare class BrowserConfig {
|
|
|
140
176
|
cache?: boolean;
|
|
141
177
|
/** See {@link BrowserConfigOptions.blacklist}. */
|
|
142
178
|
blacklist?: boolean;
|
|
143
|
-
/**
|
|
179
|
+
/** @deprecated Not read by the API, see {@link BrowserConfigOptions.unblock}. */
|
|
144
180
|
unblock?: boolean;
|
|
145
|
-
/**
|
|
181
|
+
/** @deprecated Not read by the API, see {@link BrowserConfigOptions.unblock_timeout}. */
|
|
146
182
|
unblock_timeout?: number;
|
|
147
183
|
/** See {@link BrowserConfigOptions.browser_brand}. */
|
|
148
184
|
browser_brand?: string;
|
|
@@ -166,6 +202,8 @@ export declare class BrowserConfig {
|
|
|
166
202
|
rtc_password?: string;
|
|
167
203
|
/** See {@link BrowserConfigOptions.hitl_allowed_networks}. */
|
|
168
204
|
hitl_allowed_networks?: string;
|
|
205
|
+
/** See {@link BrowserConfigOptions.downloads_stream}. */
|
|
206
|
+
downloads_stream?: boolean;
|
|
169
207
|
/**
|
|
170
208
|
* @param options Session options. See {@link BrowserConfigOptions}.
|
|
171
209
|
* @throws `Error` if `timeout` exceeds the upper bound of 1800 seconds.
|
|
@@ -173,13 +211,23 @@ export declare class BrowserConfig {
|
|
|
173
211
|
constructor(options?: BrowserConfigOptions);
|
|
174
212
|
/**
|
|
175
213
|
* Return the deterministic project salt for an api_key (`sha256(api_key)[:8]`).
|
|
176
|
-
* Matches the `X-Browser-Project-Salt` response header returned on
|
|
177
|
-
*
|
|
178
|
-
* an attach link belongs to
|
|
214
|
+
* Matches the `X-Browser-Project-Salt` response header returned on
|
|
215
|
+
* VNC-enabled Cloud Browser upgrades, where the salt is also the VNC
|
|
216
|
+
* password prefix. Useful for verifying that an attach link belongs to
|
|
217
|
+
* your project before sharing it.
|
|
179
218
|
*
|
|
180
219
|
* Uses the Web Crypto API where available (modern Node and browsers).
|
|
181
220
|
*/
|
|
182
221
|
static projectSalt(apiKey: string): Promise<string>;
|
|
222
|
+
/**
|
|
223
|
+
* Return the password a native VNC client must type to attach to a session
|
|
224
|
+
* created with this config: `<projectSalt>-<vnc_password>`.
|
|
225
|
+
*
|
|
226
|
+
* Required by the VNC TCP endpoint (port 5901), which the server salts at
|
|
227
|
+
* allocation. The WebSocket endpoint `/run/<run_id>/vnc` takes the raw
|
|
228
|
+
* `vnc_password` instead.
|
|
229
|
+
*/
|
|
230
|
+
vncClientPassword(apiKey: string): Promise<string>;
|
|
183
231
|
/**
|
|
184
232
|
* Build the WebSocket URL clients use to connect to the Cloud Browser
|
|
185
233
|
* session (compatible with Puppeteer `browserWSEndpoint` and the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browserconfig.d.ts","sourceRoot":"","sources":["../src/browserconfig.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,oBAAY,SAAS;IACnB,2EAA2E;IAC3E,UAAU,eAAe;IACzB,iFAAiF;IACjF,WAAW,gBAAgB;CAC5B;AAED,6EAA6E;AAC7E,oBAAY,eAAe;IACzB,2CAA2C;IAC3C,KAAK,UAAU;IACf,6CAA6C;IAC7C,OAAO,YAAY;IACnB,2CAA2C;IAC3C,KAAK,UAAU;
|
|
1
|
+
{"version":3,"file":"browserconfig.d.ts","sourceRoot":"","sources":["../src/browserconfig.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,oBAAY,SAAS;IACnB,2EAA2E;IAC3E,UAAU,eAAe;IACzB,iFAAiF;IACjF,WAAW,gBAAgB;CAC5B;AAED,6EAA6E;AAC7E,oBAAY,eAAe;IACzB,2CAA2C;IAC3C,KAAK,UAAU;IACf,6CAA6C;IAC7C,OAAO,YAAY;IACnB,2CAA2C;IAC3C,KAAK,UAAU;IACf,oDAAoD;IACpD,OAAO,YAAY;IACnB,6CAA6C;IAC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AG,OAAO,CAAC,MAAM,CAAC;IAWzD;;;;;;;OAOG;IACG,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAQxD;;;;;;;;OAQG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM;CAyCpD"}
|
package/esm/browserconfig.js
CHANGED
|
@@ -15,6 +15,12 @@ export var OperatingSystem;
|
|
|
15
15
|
OperatingSystem["WINDOWS"] = "windows";
|
|
16
16
|
/** Emulate a macOS browser fingerprint. */
|
|
17
17
|
OperatingSystem["MACOS"] = "macos";
|
|
18
|
+
/** Emulate an Android phone browser fingerprint. */
|
|
19
|
+
OperatingSystem["ANDROID"] = "android";
|
|
20
|
+
/** Emulate an iPhone browser fingerprint. */
|
|
21
|
+
OperatingSystem["IPHONE"] = "iphone";
|
|
22
|
+
/** Emulate an iPad browser fingerprint. */
|
|
23
|
+
OperatingSystem["IPAD"] = "ipad";
|
|
18
24
|
})(OperatingSystem || (OperatingSystem = {}));
|
|
19
25
|
/**
|
|
20
26
|
* Configuration for a Scrapfly Cloud Browser session. Builds the
|
|
@@ -55,6 +61,20 @@ export class BrowserConfig {
|
|
|
55
61
|
writable: true,
|
|
56
62
|
value: void 0
|
|
57
63
|
});
|
|
64
|
+
/** See {@link BrowserConfigOptions.lang}. */
|
|
65
|
+
Object.defineProperty(this, "lang", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
value: void 0
|
|
70
|
+
});
|
|
71
|
+
/** See {@link BrowserConfigOptions.languages}. Normalized to a comma-separated string. */
|
|
72
|
+
Object.defineProperty(this, "languages", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true,
|
|
75
|
+
writable: true,
|
|
76
|
+
value: void 0
|
|
77
|
+
});
|
|
58
78
|
/** See {@link BrowserConfigOptions.auto_close}. */
|
|
59
79
|
Object.defineProperty(this, "auto_close", {
|
|
60
80
|
enumerable: true,
|
|
@@ -146,14 +166,14 @@ export class BrowserConfig {
|
|
|
146
166
|
writable: true,
|
|
147
167
|
value: void 0
|
|
148
168
|
});
|
|
149
|
-
/**
|
|
169
|
+
/** @deprecated Not read by the API, see {@link BrowserConfigOptions.unblock}. */
|
|
150
170
|
Object.defineProperty(this, "unblock", {
|
|
151
171
|
enumerable: true,
|
|
152
172
|
configurable: true,
|
|
153
173
|
writable: true,
|
|
154
174
|
value: void 0
|
|
155
175
|
});
|
|
156
|
-
/**
|
|
176
|
+
/** @deprecated Not read by the API, see {@link BrowserConfigOptions.unblock_timeout}. */
|
|
157
177
|
Object.defineProperty(this, "unblock_timeout", {
|
|
158
178
|
enumerable: true,
|
|
159
179
|
configurable: true,
|
|
@@ -237,6 +257,13 @@ export class BrowserConfig {
|
|
|
237
257
|
writable: true,
|
|
238
258
|
value: void 0
|
|
239
259
|
});
|
|
260
|
+
/** See {@link BrowserConfigOptions.downloads_stream}. */
|
|
261
|
+
Object.defineProperty(this, "downloads_stream", {
|
|
262
|
+
enumerable: true,
|
|
263
|
+
configurable: true,
|
|
264
|
+
writable: true,
|
|
265
|
+
value: void 0
|
|
266
|
+
});
|
|
240
267
|
if (options.timeout !== undefined && options.timeout > 1800) {
|
|
241
268
|
throw new Error('timeout cannot exceed 1800 seconds (30 minutes)');
|
|
242
269
|
}
|
|
@@ -244,6 +271,14 @@ export class BrowserConfig {
|
|
|
244
271
|
this.os = options.os;
|
|
245
272
|
this.session = options.session;
|
|
246
273
|
this.country = options.country;
|
|
274
|
+
this.lang = options.lang;
|
|
275
|
+
if (Array.isArray(options.languages)) {
|
|
276
|
+
const cleaned = options.languages.map((s) => s.trim()).filter((s) => s.length > 0);
|
|
277
|
+
this.languages = cleaned.length > 0 ? cleaned.join(',') : undefined;
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
this.languages = options.languages || undefined;
|
|
281
|
+
}
|
|
247
282
|
this.auto_close = options.auto_close;
|
|
248
283
|
this.timeout = options.timeout;
|
|
249
284
|
this.debug = options.debug;
|
|
@@ -278,12 +313,14 @@ export class BrowserConfig {
|
|
|
278
313
|
else {
|
|
279
314
|
this.hitl_allowed_networks = options.hitl_allowed_networks || undefined;
|
|
280
315
|
}
|
|
316
|
+
this.downloads_stream = options.downloads_stream;
|
|
281
317
|
}
|
|
282
318
|
/**
|
|
283
319
|
* Return the deterministic project salt for an api_key (`sha256(api_key)[:8]`).
|
|
284
|
-
* Matches the `X-Browser-Project-Salt` response header returned on
|
|
285
|
-
*
|
|
286
|
-
* an attach link belongs to
|
|
320
|
+
* Matches the `X-Browser-Project-Salt` response header returned on
|
|
321
|
+
* VNC-enabled Cloud Browser upgrades, where the salt is also the VNC
|
|
322
|
+
* password prefix. Useful for verifying that an attach link belongs to
|
|
323
|
+
* your project before sharing it.
|
|
287
324
|
*
|
|
288
325
|
* Uses the Web Crypto API where available (modern Node and browsers).
|
|
289
326
|
*/
|
|
@@ -297,6 +334,21 @@ export class BrowserConfig {
|
|
|
297
334
|
}
|
|
298
335
|
return hex;
|
|
299
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* Return the password a native VNC client must type to attach to a session
|
|
339
|
+
* created with this config: `<projectSalt>-<vnc_password>`.
|
|
340
|
+
*
|
|
341
|
+
* Required by the VNC TCP endpoint (port 5901), which the server salts at
|
|
342
|
+
* allocation. The WebSocket endpoint `/run/<run_id>/vnc` takes the raw
|
|
343
|
+
* `vnc_password` instead.
|
|
344
|
+
*/
|
|
345
|
+
async vncClientPassword(apiKey) {
|
|
346
|
+
if (!this.enable_vnc || !this.vnc_password) {
|
|
347
|
+
throw new Error('enable_vnc and vnc_password must both be set on this BrowserConfig');
|
|
348
|
+
}
|
|
349
|
+
const salt = await BrowserConfig.projectSalt(apiKey);
|
|
350
|
+
return `${salt}-${this.vnc_password}`;
|
|
351
|
+
}
|
|
300
352
|
/**
|
|
301
353
|
* Build the WebSocket URL clients use to connect to the Cloud Browser
|
|
302
354
|
* session (compatible with Puppeteer `browserWSEndpoint` and the
|
|
@@ -317,6 +369,10 @@ export class BrowserConfig {
|
|
|
317
369
|
params.set('session', this.session);
|
|
318
370
|
if (this.country !== undefined)
|
|
319
371
|
params.set('country', this.country);
|
|
372
|
+
if (this.lang !== undefined)
|
|
373
|
+
params.set('lang', this.lang);
|
|
374
|
+
if (this.languages !== undefined)
|
|
375
|
+
params.set('languages', this.languages);
|
|
320
376
|
if (this.auto_close !== undefined)
|
|
321
377
|
params.set('auto_close', String(this.auto_close));
|
|
322
378
|
if (this.timeout !== undefined)
|
|
@@ -369,6 +425,8 @@ export class BrowserConfig {
|
|
|
369
425
|
params.set('rtc_password', this.rtc_password);
|
|
370
426
|
if (this.hitl_allowed_networks !== undefined)
|
|
371
427
|
params.set('hitl_allowed_networks', this.hitl_allowed_networks);
|
|
428
|
+
if (this.downloads_stream !== undefined)
|
|
429
|
+
params.set('downloads_stream', String(this.downloads_stream));
|
|
372
430
|
const baseHost = host || 'wss://browser.scrapfly.io';
|
|
373
431
|
return `${baseHost}?${params.toString()}`;
|
|
374
432
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** Base64 characters per `IO.read`: an 8 MiB message carrying 6 MiB of the file. */
|
|
2
|
+
export declare const DEFAULT_CHUNK_SIZE: number;
|
|
3
|
+
/** The largest chunk the Cloud Browser serves per `IO.read`. */
|
|
4
|
+
export declare const MAX_CHUNK_SIZE: number;
|
|
5
|
+
/** A CDP session: Puppeteer's or Playwright's `CDPSession`, or a chrome-remote-interface client. */
|
|
6
|
+
export interface CdpSession {
|
|
7
|
+
send(method: any, params?: any): Promise<any>;
|
|
8
|
+
}
|
|
9
|
+
/** A function sending one CDP command and resolving to its result. */
|
|
10
|
+
export type CdpSend = (method: string, params?: Record<string, unknown>) => Promise<any>;
|
|
11
|
+
/**
|
|
12
|
+
* One file of the session's download directory. A small file carries its base64 content in `data`. A large
|
|
13
|
+
* one, with `downloads_stream`, carries the IO handle to read in `stream` instead, and its size in bytes.
|
|
14
|
+
*/
|
|
15
|
+
export interface BrowserDownload {
|
|
16
|
+
name: string;
|
|
17
|
+
guid?: string;
|
|
18
|
+
size?: number;
|
|
19
|
+
data?: string;
|
|
20
|
+
stream?: string;
|
|
21
|
+
}
|
|
22
|
+
/** A download could not be read whole. */
|
|
23
|
+
export declare class BrowserDownloadError extends Error {
|
|
24
|
+
constructor(message: string);
|
|
25
|
+
}
|
|
26
|
+
interface StreamEntry {
|
|
27
|
+
stream: string;
|
|
28
|
+
size?: number;
|
|
29
|
+
name?: string;
|
|
30
|
+
}
|
|
31
|
+
interface GetDownloadsResult {
|
|
32
|
+
files?: Record<string, string>;
|
|
33
|
+
files_by_guid?: Record<string, string>;
|
|
34
|
+
guid_names?: Record<string, string>;
|
|
35
|
+
streams?: Record<string, StreamEntry>;
|
|
36
|
+
}
|
|
37
|
+
/** The downloads of a `ScrapiumBrowser.getDownloads` result, in either of its shapes. */
|
|
38
|
+
export declare function parseDownloads(result: GetDownloadsResult): BrowserDownload[];
|
|
39
|
+
export interface CloudBrowserDownloadsOptions {
|
|
40
|
+
/** Base64 characters per `IO.read`, rounded down to a multiple of 4. Defaults to 8 MiB, 32 MiB at most. */
|
|
41
|
+
chunkSize?: number;
|
|
42
|
+
}
|
|
43
|
+
export interface WaitForOptions {
|
|
44
|
+
/** Milliseconds before giving up. Defaults to 60000. */
|
|
45
|
+
timeout?: number;
|
|
46
|
+
/** Milliseconds between two checks. Defaults to 500. */
|
|
47
|
+
interval?: number;
|
|
48
|
+
}
|
|
49
|
+
/** Download helpers over a CDP session of a Cloud Browser. */
|
|
50
|
+
export declare class CloudBrowserDownloads {
|
|
51
|
+
readonly chunkSize: number;
|
|
52
|
+
private readonly sendCommand;
|
|
53
|
+
constructor(session: CdpSession | CdpSend, options?: CloudBrowserDownloadsOptions);
|
|
54
|
+
/** The size in bytes of every completed download, by filename. */
|
|
55
|
+
metadata(): Promise<Record<string, number>>;
|
|
56
|
+
/** Wait until `filename` is listed with the same size twice in a row, and resolve to that size. */
|
|
57
|
+
waitFor(filename: string, options?: WaitForOptions): Promise<number>;
|
|
58
|
+
/** Every download of the session: small ones with their content, large ones as handles. */
|
|
59
|
+
list(): Promise<BrowserDownload[]>;
|
|
60
|
+
/** The bytes of a download, one decoded chunk at a time. A stream handle is read once. */
|
|
61
|
+
chunks(download: BrowserDownload): AsyncGenerator<Uint8Array>;
|
|
62
|
+
/** The whole content of a download, in memory. */
|
|
63
|
+
read(download: BrowserDownload): Promise<Uint8Array>;
|
|
64
|
+
/** Write a download to `path` (a file or a directory, the current one by default) chunk by chunk. */
|
|
65
|
+
save(download: BrowserDownload, path?: string): Promise<string>;
|
|
66
|
+
/** Write every download of the session into `directory` and resolve to their paths. */
|
|
67
|
+
saveAll(directory?: string): Promise<string[]>;
|
|
68
|
+
}
|
|
69
|
+
export {};
|
|
70
|
+
//# sourceMappingURL=browserdownloads.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browserdownloads.d.ts","sourceRoot":"","sources":["../src/browserdownloads.ts"],"names":[],"mappings":"AAoBA,oFAAoF;AACpF,eAAO,MAAM,kBAAkB,QAAkB,CAAC;AAClD,gEAAgE;AAChE,eAAO,MAAM,cAAc,QAAmB,CAAC;AAK/C,oGAAoG;AACpG,MAAM,WAAW,UAAU;IAEzB,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;CAC/C;AAED,sEAAsE;AAEtE,MAAM,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAEzF;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,C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