@browserless.io/browserless 2.2.0-beta-2 → 2.2.0-beta-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/build/browsers/index.js +9 -3
- package/build/router.js +13 -6
- package/build/routes/chromium/http/content-post.body.json +15 -19
- package/build/routes/chromium/http/content-post.d.ts +1 -1
- package/build/routes/chromium/http/content-post.js +2 -4
- package/build/routes/chromium/http/content-post.query.json +1 -1
- package/build/routes/chromium/http/download-post.query.json +1 -1
- package/build/routes/chromium/http/function-post.query.json +1 -1
- package/build/routes/chromium/http/pdf-post.body.json +15 -19
- package/build/routes/chromium/http/pdf-post.d.ts +1 -1
- package/build/routes/chromium/http/pdf-post.js +10 -6
- package/build/routes/chromium/http/pdf-post.query.json +1 -1
- package/build/routes/chromium/http/performance.query.json +1 -1
- package/build/routes/chromium/http/scrape-post.body.json +15 -19
- package/build/routes/chromium/http/scrape-post.d.ts +3 -3
- package/build/routes/chromium/http/scrape-post.js +2 -4
- package/build/routes/chromium/http/scrape-post.query.json +1 -1
- package/build/routes/chromium/http/scrape-post.response.json +22 -38
- package/build/routes/chromium/http/screenshot-post.body.json +15 -19
- package/build/routes/chromium/http/screenshot-post.d.ts +1 -1
- package/build/routes/chromium/http/screenshot-post.js +2 -4
- package/build/routes/chromium/http/screenshot-post.query.json +1 -1
- package/build/routes/chromium/tests/content.spec.js +27 -1
- package/build/routes/chromium/tests/websocket.spec.js +53 -4
- package/build/routes/chromium/ws/browser.js +1 -1
- package/build/routes/chromium/ws/browser.query.json +1 -1
- package/build/routes/chromium/ws/cdp-chromium.query.json +1 -1
- package/build/routes/chromium/ws/page.query.json +1 -1
- package/build/routes/management/http/sessions-get.response.json +5 -1
- package/build/shim.js +1 -1
- package/build/types.d.ts +2 -1
- package/package.json +3 -3
- package/src/browsers/index.ts +11 -4
- package/src/router.ts +13 -7
- package/src/routes/chromium/http/content-post.ts +3 -4
- package/src/routes/chromium/http/pdf-post.ts +13 -6
- package/src/routes/chromium/http/scrape-post.ts +5 -6
- package/src/routes/chromium/http/screenshot-post.ts +3 -4
- package/src/routes/chromium/tests/content.spec.ts +28 -1
- package/src/routes/chromium/tests/websocket.spec.ts +70 -4
- package/src/routes/chromium/ws/browser.ts +1 -1
- package/src/shim.ts +1 -1
- package/src/types.ts +2 -1
- package/static/docs/swagger.json +72 -100
- package/static/function/client.js +192 -488
package/build/browsers/index.js
CHANGED
|
@@ -108,6 +108,10 @@ export class BrowserManager {
|
|
|
108
108
|
close = async (browser, session) => {
|
|
109
109
|
const cleanupACtions = [];
|
|
110
110
|
this.debug(`${session.numbConnected} Client(s) are currently connected`);
|
|
111
|
+
// Don't close if there's clients still connected
|
|
112
|
+
if (session.numbConnected > 0) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
111
115
|
this.debug(`Closing browser session`);
|
|
112
116
|
cleanupACtions.push(() => browser.close());
|
|
113
117
|
if (session.isTempDataDir) {
|
|
@@ -150,10 +154,12 @@ export class BrowserManager {
|
|
|
150
154
|
if (req.parsed.pathname.includes('/devtools/browser')) {
|
|
151
155
|
const sessions = Array.from(this.browsers);
|
|
152
156
|
const id = req.parsed.pathname.split('/').pop();
|
|
153
|
-
const
|
|
154
|
-
if (
|
|
157
|
+
const found = sessions.find(([b]) => b.wsEndpoint()?.includes(req.parsed.pathname));
|
|
158
|
+
if (found) {
|
|
159
|
+
const [browser, session] = found;
|
|
160
|
+
++session.numbConnected;
|
|
155
161
|
this.debug(`Located browser with ID ${id}`);
|
|
156
|
-
return browser
|
|
162
|
+
return browser;
|
|
157
163
|
}
|
|
158
164
|
throw new NotFound(`Couldn't locate browser "${id}" for request "${req.parsed.pathname}"`);
|
|
159
165
|
}
|
package/build/router.js
CHANGED
|
@@ -46,15 +46,22 @@ export class Router {
|
|
|
46
46
|
return Promise.resolve();
|
|
47
47
|
}
|
|
48
48
|
if (!browser) {
|
|
49
|
-
return writeResponse(res, 500, `Error loading the browser
|
|
50
|
-
}
|
|
51
|
-
if (!isConnected(res)) {
|
|
52
|
-
this.log(`HTTP Request has closed prior to running`);
|
|
53
|
-
return Promise.resolve();
|
|
49
|
+
return writeResponse(res, 500, `Error loading the browser`);
|
|
54
50
|
}
|
|
55
51
|
try {
|
|
56
52
|
this.verbose(`Running found HTTP handler.`);
|
|
57
|
-
return await
|
|
53
|
+
return await Promise.race([
|
|
54
|
+
handler(req, res, browser),
|
|
55
|
+
new Promise((resolve, reject) => {
|
|
56
|
+
res.once('close', () => {
|
|
57
|
+
if (!res.writableEnded) {
|
|
58
|
+
reject(new Error(`Request closed prior to writing results`));
|
|
59
|
+
}
|
|
60
|
+
this.verbose(`Response has been written, resolving`);
|
|
61
|
+
resolve(null);
|
|
62
|
+
});
|
|
63
|
+
}),
|
|
64
|
+
]);
|
|
58
65
|
}
|
|
59
66
|
finally {
|
|
60
67
|
this.verbose(`HTTP Request handler has finished.`);
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"cookies": {
|
|
24
24
|
"type": "array",
|
|
25
25
|
"items": {
|
|
26
|
-
"$ref": "#/definitions/
|
|
26
|
+
"$ref": "#/definitions/CookieParam"
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"emulateMediaType": {
|
|
@@ -230,7 +230,7 @@
|
|
|
230
230
|
"username"
|
|
231
231
|
]
|
|
232
232
|
},
|
|
233
|
-
"
|
|
233
|
+
"CookieParam": {
|
|
234
234
|
"description": "Cookie parameter object",
|
|
235
235
|
"type": "object",
|
|
236
236
|
"properties": {
|
|
@@ -243,7 +243,7 @@
|
|
|
243
243
|
"type": "string"
|
|
244
244
|
},
|
|
245
245
|
"url": {
|
|
246
|
-
"description": "The request-URI to associate with the setting of the cookie. This value can affect
|
|
246
|
+
"description": "The request-URI to associate with the setting of the cookie. This value can affect\nthe default domain, path, and source scheme values of the created cookie.",
|
|
247
247
|
"type": "string"
|
|
248
248
|
},
|
|
249
249
|
"domain": {
|
|
@@ -276,7 +276,7 @@
|
|
|
276
276
|
"type": "number"
|
|
277
277
|
},
|
|
278
278
|
"priority": {
|
|
279
|
-
"description": "Cookie Priority.",
|
|
279
|
+
"description": "Cookie Priority. Supported only in Chrome.",
|
|
280
280
|
"enum": [
|
|
281
281
|
"High",
|
|
282
282
|
"Low",
|
|
@@ -285,11 +285,11 @@
|
|
|
285
285
|
"type": "string"
|
|
286
286
|
},
|
|
287
287
|
"sameParty": {
|
|
288
|
-
"description": "True if cookie is SameParty.",
|
|
288
|
+
"description": "True if cookie is SameParty. Supported only in Chrome.",
|
|
289
289
|
"type": "boolean"
|
|
290
290
|
},
|
|
291
291
|
"sourceScheme": {
|
|
292
|
-
"description": "Cookie source scheme type.",
|
|
292
|
+
"description": "Cookie source scheme type. Supported only in Chrome.",
|
|
293
293
|
"enum": [
|
|
294
294
|
"NonSecure",
|
|
295
295
|
"Secure",
|
|
@@ -297,12 +297,8 @@
|
|
|
297
297
|
],
|
|
298
298
|
"type": "string"
|
|
299
299
|
},
|
|
300
|
-
"sourcePort": {
|
|
301
|
-
"description": "Cookie source port. Valid values are {-1, [1, 65535]}, -1 indicates an unspecified port.\nAn unspecified port value allows protocol clients to emulate legacy cookie scope for the port.\nThis is a temporary ability and it will be removed in the future.",
|
|
302
|
-
"type": "number"
|
|
303
|
-
},
|
|
304
300
|
"partitionKey": {
|
|
305
|
-
"description": "Cookie partition key. The site of the top-level URL the browser was visiting at the
|
|
301
|
+
"description": "Cookie partition key. The site of the top-level URL the browser was visiting at the\nstart of the request to the endpoint that set the cookie. If not set, the cookie will\nbe set as not partitioned.",
|
|
306
302
|
"type": "string"
|
|
307
303
|
}
|
|
308
304
|
},
|
|
@@ -398,14 +394,14 @@
|
|
|
398
394
|
"length": {
|
|
399
395
|
"type": "number"
|
|
400
396
|
},
|
|
401
|
-
"__@toStringTag@
|
|
397
|
+
"__@toStringTag@10774": {
|
|
402
398
|
"type": "string",
|
|
403
399
|
"const": "Uint8Array"
|
|
404
400
|
}
|
|
405
401
|
},
|
|
406
402
|
"required": [
|
|
407
403
|
"BYTES_PER_ELEMENT",
|
|
408
|
-
"__@toStringTag@
|
|
404
|
+
"__@toStringTag@10774",
|
|
409
405
|
"buffer",
|
|
410
406
|
"byteLength",
|
|
411
407
|
"byteOffset",
|
|
@@ -440,13 +436,13 @@
|
|
|
440
436
|
"byteLength": {
|
|
441
437
|
"type": "number"
|
|
442
438
|
},
|
|
443
|
-
"__@toStringTag@
|
|
439
|
+
"__@toStringTag@10774": {
|
|
444
440
|
"type": "string"
|
|
445
441
|
}
|
|
446
442
|
},
|
|
447
443
|
"additionalProperties": false,
|
|
448
444
|
"required": [
|
|
449
|
-
"__@toStringTag@
|
|
445
|
+
"__@toStringTag@10774",
|
|
450
446
|
"byteLength"
|
|
451
447
|
]
|
|
452
448
|
},
|
|
@@ -456,18 +452,18 @@
|
|
|
456
452
|
"byteLength": {
|
|
457
453
|
"type": "number"
|
|
458
454
|
},
|
|
459
|
-
"__@species@
|
|
455
|
+
"__@species@10875": {
|
|
460
456
|
"$ref": "#/definitions/SharedArrayBuffer"
|
|
461
457
|
},
|
|
462
|
-
"__@toStringTag@
|
|
458
|
+
"__@toStringTag@10774": {
|
|
463
459
|
"type": "string",
|
|
464
460
|
"const": "SharedArrayBuffer"
|
|
465
461
|
}
|
|
466
462
|
},
|
|
467
463
|
"additionalProperties": false,
|
|
468
464
|
"required": [
|
|
469
|
-
"__@species@
|
|
470
|
-
"__@toStringTag@
|
|
465
|
+
"__@species@10875",
|
|
466
|
+
"__@toStringTag@10774",
|
|
471
467
|
"byteLength"
|
|
472
468
|
]
|
|
473
469
|
},
|
|
@@ -22,7 +22,7 @@ export interface BodySchema {
|
|
|
22
22
|
waitForEvent?: WaitForEventOptions;
|
|
23
23
|
waitForFunction?: WaitForFunctionOptions;
|
|
24
24
|
waitForSelector?: WaitForSelectorOptions;
|
|
25
|
-
waitForTimeout?:
|
|
25
|
+
waitForTimeout?: number;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* An HTML payload of the website or HTML after JavaScript
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { APITags, BadRequest, BrowserHTTPRoute, CDPChromium, HTTPRoutes, Methods, bestAttemptCatch, contentTypes, noop, waitForEvent as waitForEvt, waitForFunction as waitForFn, writeResponse, } from '@browserless.io/browserless';
|
|
1
|
+
import { APITags, BadRequest, BrowserHTTPRoute, CDPChromium, HTTPRoutes, Methods, bestAttemptCatch, contentTypes, noop, sleep, waitForEvent as waitForEvt, waitForFunction as waitForFn, writeResponse, } from '@browserless.io/browserless';
|
|
2
2
|
export default class ContentPostRoute extends BrowserHTTPRoute {
|
|
3
3
|
accepts = [contentTypes.json];
|
|
4
4
|
auth = true;
|
|
@@ -73,9 +73,7 @@ export default class ContentPostRoute extends BrowserHTTPRoute {
|
|
|
73
73
|
}
|
|
74
74
|
const gotoResponse = await gotoCall(content, gotoOptions).catch(bestAttemptCatch(bestAttempt));
|
|
75
75
|
if (waitForTimeout) {
|
|
76
|
-
await
|
|
77
|
-
.waitForTimeout(waitForTimeout)
|
|
78
|
-
.catch(bestAttemptCatch(bestAttempt));
|
|
76
|
+
await sleep(waitForTimeout).catch(bestAttemptCatch(bestAttempt));
|
|
79
77
|
}
|
|
80
78
|
if (waitForFunction) {
|
|
81
79
|
await waitForFn(page, waitForFunction).catch(bestAttemptCatch(bestAttempt));
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"cookies": {
|
|
27
27
|
"type": "array",
|
|
28
28
|
"items": {
|
|
29
|
-
"$ref": "#/definitions/
|
|
29
|
+
"$ref": "#/definitions/CookieParam"
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"emulateMediaType": {
|
|
@@ -235,7 +235,7 @@
|
|
|
235
235
|
"username"
|
|
236
236
|
]
|
|
237
237
|
},
|
|
238
|
-
"
|
|
238
|
+
"CookieParam": {
|
|
239
239
|
"description": "Cookie parameter object",
|
|
240
240
|
"type": "object",
|
|
241
241
|
"properties": {
|
|
@@ -248,7 +248,7 @@
|
|
|
248
248
|
"type": "string"
|
|
249
249
|
},
|
|
250
250
|
"url": {
|
|
251
|
-
"description": "The request-URI to associate with the setting of the cookie. This value can affect
|
|
251
|
+
"description": "The request-URI to associate with the setting of the cookie. This value can affect\nthe default domain, path, and source scheme values of the created cookie.",
|
|
252
252
|
"type": "string"
|
|
253
253
|
},
|
|
254
254
|
"domain": {
|
|
@@ -281,7 +281,7 @@
|
|
|
281
281
|
"type": "number"
|
|
282
282
|
},
|
|
283
283
|
"priority": {
|
|
284
|
-
"description": "Cookie Priority.",
|
|
284
|
+
"description": "Cookie Priority. Supported only in Chrome.",
|
|
285
285
|
"enum": [
|
|
286
286
|
"High",
|
|
287
287
|
"Low",
|
|
@@ -290,11 +290,11 @@
|
|
|
290
290
|
"type": "string"
|
|
291
291
|
},
|
|
292
292
|
"sameParty": {
|
|
293
|
-
"description": "True if cookie is SameParty.",
|
|
293
|
+
"description": "True if cookie is SameParty. Supported only in Chrome.",
|
|
294
294
|
"type": "boolean"
|
|
295
295
|
},
|
|
296
296
|
"sourceScheme": {
|
|
297
|
-
"description": "Cookie source scheme type.",
|
|
297
|
+
"description": "Cookie source scheme type. Supported only in Chrome.",
|
|
298
298
|
"enum": [
|
|
299
299
|
"NonSecure",
|
|
300
300
|
"Secure",
|
|
@@ -302,12 +302,8 @@
|
|
|
302
302
|
],
|
|
303
303
|
"type": "string"
|
|
304
304
|
},
|
|
305
|
-
"sourcePort": {
|
|
306
|
-
"description": "Cookie source port. Valid values are {-1, [1, 65535]}, -1 indicates an unspecified port.\nAn unspecified port value allows protocol clients to emulate legacy cookie scope for the port.\nThis is a temporary ability and it will be removed in the future.",
|
|
307
|
-
"type": "number"
|
|
308
|
-
},
|
|
309
305
|
"partitionKey": {
|
|
310
|
-
"description": "Cookie partition key. The site of the top-level URL the browser was visiting at the
|
|
306
|
+
"description": "Cookie partition key. The site of the top-level URL the browser was visiting at the\nstart of the request to the endpoint that set the cookie. If not set, the cookie will\nbe set as not partitioned.",
|
|
311
307
|
"type": "string"
|
|
312
308
|
}
|
|
313
309
|
},
|
|
@@ -542,14 +538,14 @@
|
|
|
542
538
|
"length": {
|
|
543
539
|
"type": "number"
|
|
544
540
|
},
|
|
545
|
-
"__@toStringTag@
|
|
541
|
+
"__@toStringTag@85666": {
|
|
546
542
|
"type": "string",
|
|
547
543
|
"const": "Uint8Array"
|
|
548
544
|
}
|
|
549
545
|
},
|
|
550
546
|
"required": [
|
|
551
547
|
"BYTES_PER_ELEMENT",
|
|
552
|
-
"__@toStringTag@
|
|
548
|
+
"__@toStringTag@85666",
|
|
553
549
|
"buffer",
|
|
554
550
|
"byteLength",
|
|
555
551
|
"byteOffset",
|
|
@@ -584,13 +580,13 @@
|
|
|
584
580
|
"byteLength": {
|
|
585
581
|
"type": "number"
|
|
586
582
|
},
|
|
587
|
-
"__@toStringTag@
|
|
583
|
+
"__@toStringTag@85666": {
|
|
588
584
|
"type": "string"
|
|
589
585
|
}
|
|
590
586
|
},
|
|
591
587
|
"additionalProperties": false,
|
|
592
588
|
"required": [
|
|
593
|
-
"__@toStringTag@
|
|
589
|
+
"__@toStringTag@85666",
|
|
594
590
|
"byteLength"
|
|
595
591
|
]
|
|
596
592
|
},
|
|
@@ -600,18 +596,18 @@
|
|
|
600
596
|
"byteLength": {
|
|
601
597
|
"type": "number"
|
|
602
598
|
},
|
|
603
|
-
"__@species@
|
|
599
|
+
"__@species@85767": {
|
|
604
600
|
"$ref": "#/definitions/SharedArrayBuffer"
|
|
605
601
|
},
|
|
606
|
-
"__@toStringTag@
|
|
602
|
+
"__@toStringTag@85666": {
|
|
607
603
|
"type": "string",
|
|
608
604
|
"const": "SharedArrayBuffer"
|
|
609
605
|
}
|
|
610
606
|
},
|
|
611
607
|
"additionalProperties": false,
|
|
612
608
|
"required": [
|
|
613
|
-
"__@species@
|
|
614
|
-
"__@toStringTag@
|
|
609
|
+
"__@species@85767",
|
|
610
|
+
"__@toStringTag@85666",
|
|
615
611
|
"byteLength"
|
|
616
612
|
]
|
|
617
613
|
},
|
|
@@ -24,7 +24,7 @@ export interface BodySchema {
|
|
|
24
24
|
waitForEvent?: WaitForEventOptions;
|
|
25
25
|
waitForFunction?: WaitForFunctionOptions;
|
|
26
26
|
waitForSelector?: WaitForSelectorOptions;
|
|
27
|
-
waitForTimeout?:
|
|
27
|
+
waitForTimeout?: number;
|
|
28
28
|
}
|
|
29
29
|
export interface QuerySchema extends SystemQueryParameters {
|
|
30
30
|
launch?: CDPLaunchOptions | string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { APITags, BadRequest, BrowserHTTPRoute, CDPChromium, HTTPRoutes, Methods, bestAttemptCatch, contentTypes, dedent, noop, waitForEvent as waitForEvt, waitForFunction as waitForFn, writeResponse, } from '@browserless.io/browserless';
|
|
1
|
+
import { APITags, BadRequest, BrowserHTTPRoute, CDPChromium, HTTPRoutes, Methods, bestAttemptCatch, contentTypes, dedent, noop, sleep, waitForEvent as waitForEvt, waitForFunction as waitForFn, writeResponse, } from '@browserless.io/browserless';
|
|
2
|
+
import { Stream } from 'stream';
|
|
2
3
|
export default class PDFPost extends BrowserHTTPRoute {
|
|
3
4
|
accepts = [contentTypes.json];
|
|
4
5
|
auth = true;
|
|
@@ -23,7 +24,7 @@ export default class PDFPost extends BrowserHTTPRoute {
|
|
|
23
24
|
return;
|
|
24
25
|
}
|
|
25
26
|
res.setHeader('Content-Type', contentType);
|
|
26
|
-
const { url, gotoOptions, authenticate, html, addScriptTag = [], addStyleTag = [], cookies = [], emulateMediaType, rejectRequestPattern = [], requestInterceptors = [], rejectResourceTypes = [], options, setExtraHTTPHeaders, setJavaScriptEnabled, userAgent, viewport, waitForFunction, waitForSelector,
|
|
27
|
+
const { url, gotoOptions, authenticate, html, addScriptTag = [], addStyleTag = [], cookies = [], emulateMediaType, rejectRequestPattern = [], requestInterceptors = [], rejectResourceTypes = [], options, setExtraHTTPHeaders, setJavaScriptEnabled, userAgent, viewport, waitForEvent, waitForFunction, waitForSelector, waitForTimeout, bestAttempt = false, } = req.body;
|
|
27
28
|
const content = url || html;
|
|
28
29
|
if (!content) {
|
|
29
30
|
throw new BadRequest(`One of "url" or "html" properties are required.`);
|
|
@@ -78,6 +79,9 @@ export default class PDFPost extends BrowserHTTPRoute {
|
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
const gotoResponse = await gotoCall(content, gotoOptions).catch(bestAttemptCatch(bestAttempt));
|
|
82
|
+
if (waitForTimeout) {
|
|
83
|
+
await sleep(waitForTimeout).catch(bestAttemptCatch(bestAttempt));
|
|
84
|
+
}
|
|
81
85
|
if (waitForFunction) {
|
|
82
86
|
await waitForFn(page, waitForFunction).catch(bestAttemptCatch(bestAttempt));
|
|
83
87
|
}
|
|
@@ -102,10 +106,10 @@ export default class PDFPost extends BrowserHTTPRoute {
|
|
|
102
106
|
res.setHeader(key, value);
|
|
103
107
|
}
|
|
104
108
|
}
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
+
const pdfBuffer = await page.pdf(options);
|
|
110
|
+
const readStream = new Stream.PassThrough();
|
|
111
|
+
readStream.end(pdfBuffer);
|
|
112
|
+
await new Promise((r) => readStream.pipe(res).once('close', r));
|
|
109
113
|
page.close().catch(noop);
|
|
110
114
|
};
|
|
111
115
|
}
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"cookies": {
|
|
24
24
|
"type": "array",
|
|
25
25
|
"items": {
|
|
26
|
-
"$ref": "#/definitions/
|
|
26
|
+
"$ref": "#/definitions/CookieParam"
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"debugOpts": {
|
|
@@ -241,7 +241,7 @@
|
|
|
241
241
|
"username"
|
|
242
242
|
]
|
|
243
243
|
},
|
|
244
|
-
"
|
|
244
|
+
"CookieParam": {
|
|
245
245
|
"description": "Cookie parameter object",
|
|
246
246
|
"type": "object",
|
|
247
247
|
"properties": {
|
|
@@ -254,7 +254,7 @@
|
|
|
254
254
|
"type": "string"
|
|
255
255
|
},
|
|
256
256
|
"url": {
|
|
257
|
-
"description": "The request-URI to associate with the setting of the cookie. This value can affect
|
|
257
|
+
"description": "The request-URI to associate with the setting of the cookie. This value can affect\nthe default domain, path, and source scheme values of the created cookie.",
|
|
258
258
|
"type": "string"
|
|
259
259
|
},
|
|
260
260
|
"domain": {
|
|
@@ -287,7 +287,7 @@
|
|
|
287
287
|
"type": "number"
|
|
288
288
|
},
|
|
289
289
|
"priority": {
|
|
290
|
-
"description": "Cookie Priority.",
|
|
290
|
+
"description": "Cookie Priority. Supported only in Chrome.",
|
|
291
291
|
"enum": [
|
|
292
292
|
"High",
|
|
293
293
|
"Low",
|
|
@@ -296,11 +296,11 @@
|
|
|
296
296
|
"type": "string"
|
|
297
297
|
},
|
|
298
298
|
"sameParty": {
|
|
299
|
-
"description": "True if cookie is SameParty.",
|
|
299
|
+
"description": "True if cookie is SameParty. Supported only in Chrome.",
|
|
300
300
|
"type": "boolean"
|
|
301
301
|
},
|
|
302
302
|
"sourceScheme": {
|
|
303
|
-
"description": "Cookie source scheme type.",
|
|
303
|
+
"description": "Cookie source scheme type. Supported only in Chrome.",
|
|
304
304
|
"enum": [
|
|
305
305
|
"NonSecure",
|
|
306
306
|
"Secure",
|
|
@@ -308,12 +308,8 @@
|
|
|
308
308
|
],
|
|
309
309
|
"type": "string"
|
|
310
310
|
},
|
|
311
|
-
"sourcePort": {
|
|
312
|
-
"description": "Cookie source port. Valid values are {-1, [1, 65535]}, -1 indicates an unspecified port.\nAn unspecified port value allows protocol clients to emulate legacy cookie scope for the port.\nThis is a temporary ability and it will be removed in the future.",
|
|
313
|
-
"type": "number"
|
|
314
|
-
},
|
|
315
311
|
"partitionKey": {
|
|
316
|
-
"description": "Cookie partition key. The site of the top-level URL the browser was visiting at the
|
|
312
|
+
"description": "Cookie partition key. The site of the top-level URL the browser was visiting at the\nstart of the request to the endpoint that set the cookie. If not set, the cookie will\nbe set as not partitioned.",
|
|
317
313
|
"type": "string"
|
|
318
314
|
}
|
|
319
315
|
},
|
|
@@ -445,14 +441,14 @@
|
|
|
445
441
|
"length": {
|
|
446
442
|
"type": "number"
|
|
447
443
|
},
|
|
448
|
-
"__@toStringTag@
|
|
444
|
+
"__@toStringTag@96598": {
|
|
449
445
|
"type": "string",
|
|
450
446
|
"const": "Uint8Array"
|
|
451
447
|
}
|
|
452
448
|
},
|
|
453
449
|
"required": [
|
|
454
450
|
"BYTES_PER_ELEMENT",
|
|
455
|
-
"__@toStringTag@
|
|
451
|
+
"__@toStringTag@96598",
|
|
456
452
|
"buffer",
|
|
457
453
|
"byteLength",
|
|
458
454
|
"byteOffset",
|
|
@@ -487,13 +483,13 @@
|
|
|
487
483
|
"byteLength": {
|
|
488
484
|
"type": "number"
|
|
489
485
|
},
|
|
490
|
-
"__@toStringTag@
|
|
486
|
+
"__@toStringTag@96598": {
|
|
491
487
|
"type": "string"
|
|
492
488
|
}
|
|
493
489
|
},
|
|
494
490
|
"additionalProperties": false,
|
|
495
491
|
"required": [
|
|
496
|
-
"__@toStringTag@
|
|
492
|
+
"__@toStringTag@96598",
|
|
497
493
|
"byteLength"
|
|
498
494
|
]
|
|
499
495
|
},
|
|
@@ -503,18 +499,18 @@
|
|
|
503
499
|
"byteLength": {
|
|
504
500
|
"type": "number"
|
|
505
501
|
},
|
|
506
|
-
"__@species@
|
|
502
|
+
"__@species@96699": {
|
|
507
503
|
"$ref": "#/definitions/SharedArrayBuffer"
|
|
508
504
|
},
|
|
509
|
-
"__@toStringTag@
|
|
505
|
+
"__@toStringTag@96598": {
|
|
510
506
|
"type": "string",
|
|
511
507
|
"const": "SharedArrayBuffer"
|
|
512
508
|
}
|
|
513
509
|
},
|
|
514
510
|
"additionalProperties": false,
|
|
515
511
|
"required": [
|
|
516
|
-
"__@species@
|
|
517
|
-
"__@toStringTag@
|
|
512
|
+
"__@species@96699",
|
|
513
|
+
"__@toStringTag@96598",
|
|
518
514
|
"byteLength"
|
|
519
515
|
]
|
|
520
516
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { APITags, BrowserHTTPRoute, BrowserInstance, CDPChromium, CDPLaunchOptions, HTTPRoutes, InBoundRequest, Methods, OutBoundRequest, Request, ScrapeDebugOptions, ScrapeElementSelector, SystemQueryParameters, WaitForEventOptions, WaitForFunctionOptions, WaitForSelectorOptions, bestAttempt, contentTypes, rejectRequestPattern, rejectResourceTypes, requestInterceptors } from '@browserless.io/browserless';
|
|
3
|
-
import {
|
|
3
|
+
import { Cookie, Page } from 'puppeteer-core';
|
|
4
4
|
import { ServerResponse } from 'http';
|
|
5
5
|
export interface BodySchema {
|
|
6
6
|
addScriptTag?: Array<Parameters<Page['addScriptTag']>[0]>;
|
|
@@ -24,7 +24,7 @@ export interface BodySchema {
|
|
|
24
24
|
waitForEvent?: WaitForEventOptions;
|
|
25
25
|
waitForFunction?: WaitForFunctionOptions;
|
|
26
26
|
waitForSelector?: WaitForSelectorOptions;
|
|
27
|
-
waitForTimeout?:
|
|
27
|
+
waitForTimeout?: number;
|
|
28
28
|
}
|
|
29
29
|
export type QuerySchema = SystemQueryParameters & {
|
|
30
30
|
launch?: CDPLaunchOptions | string;
|
|
@@ -89,7 +89,7 @@ export interface ResponseSchema {
|
|
|
89
89
|
/**
|
|
90
90
|
* List of cookies for the site or null
|
|
91
91
|
*/
|
|
92
|
-
cookies:
|
|
92
|
+
cookies: Cookie[] | null;
|
|
93
93
|
/**
|
|
94
94
|
* The HTML string of the website or null
|
|
95
95
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { APITags, BadRequest, BrowserHTTPRoute, CDPChromium, HTTPRoutes, Methods, Timeout, bestAttemptCatch, contentTypes, debugScreenshotOpts, dedent, jsonResponse, noop, waitForEvent as waitForEvt, waitForFunction as waitForFn, } from '@browserless.io/browserless';
|
|
1
|
+
import { APITags, BadRequest, BrowserHTTPRoute, CDPChromium, HTTPRoutes, Methods, Timeout, bestAttemptCatch, contentTypes, debugScreenshotOpts, dedent, jsonResponse, noop, sleep, waitForEvent as waitForEvt, waitForFunction as waitForFn, } from '@browserless.io/browserless';
|
|
2
2
|
const scrape = async (elements) => {
|
|
3
3
|
const wait = (selector, timeout = 30000) => {
|
|
4
4
|
return new Promise((resolve, reject) => {
|
|
@@ -141,9 +141,7 @@ export default class ScrapePost extends BrowserHTTPRoute {
|
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
if (waitForTimeout) {
|
|
144
|
-
await
|
|
145
|
-
.waitForTimeout(waitForTimeout)
|
|
146
|
-
.catch(bestAttemptCatch(bestAttempt));
|
|
144
|
+
await sleep(waitForTimeout).catch(bestAttemptCatch(bestAttempt));
|
|
147
145
|
}
|
|
148
146
|
if (waitForFunction) {
|
|
149
147
|
await waitForFn(page, waitForFunction).catch(bestAttemptCatch(bestAttempt));
|