@browserless.io/browserless 2.5.0-beta-1 → 2.5.0-beta-2
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/bin/browserless.js +1 -1
- package/bin/scaffold/README.md +1 -1
- package/build/browserless.d.ts +1 -1
- package/build/browserless.js +1 -0
- package/build/browsers/index.d.ts +2 -1
- package/build/hooks.d.ts +14 -5
- package/build/hooks.js +23 -12
- package/build/routes/chrome/http/pdf.post.body.json +8 -8
- package/build/routes/chrome/http/scrape.post.body.json +8 -8
- package/build/routes/chrome/http/screenshot.post.body.json +8 -8
- package/build/routes/chromium/http/content.post.body.json +8 -8
- package/build/routes/chromium/http/pdf.post.body.json +8 -8
- package/build/types.d.ts +2 -2
- package/build/utils.js +4 -9
- package/external/after.js +1 -1
- package/external/before.js +1 -1
- package/external/browser.js +1 -1
- package/external/page.js +1 -1
- package/package.json +1 -1
- package/src/browserless.ts +1 -0
- package/src/browsers/index.ts +2 -1
- package/src/hooks.ts +30 -12
- package/src/types.ts +2 -2
- package/src/utils.ts +8 -10
- package/static/docs/swagger.json +1 -1
- package/static/docs/swagger.min.json +1 -1
package/bin/browserless.js
CHANGED
|
@@ -170,7 +170,7 @@ const start = async (dev = false) => {
|
|
|
170
170
|
importDefault(files, 'token'),
|
|
171
171
|
importDefault(files, 'webhooks'),
|
|
172
172
|
importDefault(files, 'disabled-routes'),
|
|
173
|
-
importDefault(files,'
|
|
173
|
+
importDefault(files, 'hooks'),
|
|
174
174
|
]);
|
|
175
175
|
|
|
176
176
|
log(`Starting Browserless`);
|
package/bin/scaffold/README.md
CHANGED
|
@@ -477,7 +477,7 @@ export class Hooks extends EventEmitter {
|
|
|
477
477
|
// Can be used to inject behaviors or add events to a page's lifecycle.
|
|
478
478
|
// "meta" property is a parsed URL of the original incoming request.
|
|
479
479
|
// No return value or type required.
|
|
480
|
-
page(args: { meta: URL
|
|
480
|
+
page(args: { meta: URL; page: puppeteer.Page }): Promise<void> {
|
|
481
481
|
return Promise.resolve(undefined);
|
|
482
482
|
}
|
|
483
483
|
|
package/build/browserless.d.ts
CHANGED
|
@@ -42,6 +42,6 @@ export declare class Browserless extends EventEmitter {
|
|
|
42
42
|
addHTTPRoute(httpRouteFilePath: string): void;
|
|
43
43
|
addWebSocketRoute(webSocketRouteFilePath: string): void;
|
|
44
44
|
setPort(port: number): void;
|
|
45
|
-
stop(): Promise<[void | undefined, void, void, void, void, void, void, void, void, void]>;
|
|
45
|
+
stop(): Promise<[void | undefined, void, void, void, void, void, void, void, void, void, void]>;
|
|
46
46
|
start(): Promise<void>;
|
|
47
47
|
}
|
package/build/browserless.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="debug" />
|
|
2
2
|
import { BrowserHTTPRoute, BrowserInstance, BrowserWebsocketRoute, BrowserlessSession, BrowserlessSessionJSON, CDPJSONPayload, ChromiumCDP, Config, Hooks, Request } from '@browserless.io/browserless';
|
|
3
|
+
import { Page } from 'puppeteer-core';
|
|
3
4
|
export declare class BrowserManager {
|
|
4
5
|
protected config: Config;
|
|
5
6
|
protected hooks: Hooks;
|
|
@@ -12,7 +13,7 @@ export declare class BrowserManager {
|
|
|
12
13
|
constructor(config: Config, hooks: Hooks);
|
|
13
14
|
private browserIsChrome;
|
|
14
15
|
protected removeUserDataDir: (userDataDir: string | null) => Promise<void>;
|
|
15
|
-
protected onNewPage: (req: Request, page:
|
|
16
|
+
protected onNewPage: (req: Request, page: Page) => Promise<void>;
|
|
16
17
|
/**
|
|
17
18
|
* Returns the /json/protocol API contents from Chromium or Chrome, whichever is installed,
|
|
18
19
|
* and modifies URLs to set them to the appropriate addresses configured.
|
package/build/hooks.d.ts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import { AfterResponse, BeforeRequest, BrowserHook, PageHook } from '@browserless.io/browserless';
|
|
2
3
|
import { EventEmitter } from 'events';
|
|
3
4
|
export declare class Hooks extends EventEmitter {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
before(args: BeforeRequest): Promise<boolean>;
|
|
6
|
+
after(args: AfterResponse): Promise<unknown>;
|
|
7
|
+
page(args: PageHook): Promise<unknown>;
|
|
8
|
+
browser(args: BrowserHook): Promise<unknown>;
|
|
9
|
+
/**
|
|
10
|
+
* Implement any browserless-core-specific shutdown logic here.
|
|
11
|
+
* Calls the empty-SDK stop method for downstream implementations.
|
|
12
|
+
*/
|
|
13
|
+
shutdown: () => Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Left blank for downstream SDK modules to optionally implement.
|
|
16
|
+
*/
|
|
17
|
+
stop: () => void;
|
|
9
18
|
}
|
package/build/hooks.js
CHANGED
|
@@ -1,26 +1,37 @@
|
|
|
1
|
-
// @ts-nocheck Unknown external files
|
|
2
1
|
import { EventEmitter } from 'events';
|
|
3
2
|
// KEPT for backwards compatibility reasons since some downstream
|
|
4
3
|
// docker images will override these files to inject their own hook
|
|
5
4
|
// behaviors
|
|
5
|
+
// @ts-ignore
|
|
6
6
|
import { default as afterRequest } from '../external/after.js';
|
|
7
|
+
// @ts-ignore
|
|
7
8
|
import { default as beforeRequest } from '../external/before.js';
|
|
9
|
+
// @ts-ignore
|
|
8
10
|
import { default as browserHook } from '../external/browser.js';
|
|
11
|
+
// @ts-ignore
|
|
9
12
|
import { default as pageHook } from '../external/page.js';
|
|
10
13
|
export class Hooks extends EventEmitter {
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
before(args) {
|
|
15
|
+
return beforeRequest(args);
|
|
13
16
|
}
|
|
14
|
-
|
|
15
|
-
return
|
|
17
|
+
after(args) {
|
|
18
|
+
return afterRequest(args);
|
|
16
19
|
}
|
|
17
|
-
|
|
18
|
-
return
|
|
20
|
+
page(args) {
|
|
21
|
+
return pageHook(args);
|
|
19
22
|
}
|
|
20
|
-
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
browser(...args) {
|
|
24
|
-
return browserHook(...args);
|
|
23
|
+
browser(args) {
|
|
24
|
+
return browserHook(args);
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Implement any browserless-core-specific shutdown logic here.
|
|
28
|
+
* Calls the empty-SDK stop method for downstream implementations.
|
|
29
|
+
*/
|
|
30
|
+
shutdown = async () => {
|
|
31
|
+
await this.stop();
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Left blank for downstream SDK modules to optionally implement.
|
|
35
|
+
*/
|
|
36
|
+
stop = () => { };
|
|
26
37
|
}
|
|
@@ -535,14 +535,14 @@
|
|
|
535
535
|
"length": {
|
|
536
536
|
"type": "number"
|
|
537
537
|
},
|
|
538
|
-
"__@toStringTag@
|
|
538
|
+
"__@toStringTag@75984": {
|
|
539
539
|
"type": "string",
|
|
540
540
|
"const": "Uint8Array"
|
|
541
541
|
}
|
|
542
542
|
},
|
|
543
543
|
"required": [
|
|
544
544
|
"BYTES_PER_ELEMENT",
|
|
545
|
-
"__@toStringTag@
|
|
545
|
+
"__@toStringTag@75984",
|
|
546
546
|
"buffer",
|
|
547
547
|
"byteLength",
|
|
548
548
|
"byteOffset",
|
|
@@ -577,13 +577,13 @@
|
|
|
577
577
|
"byteLength": {
|
|
578
578
|
"type": "number"
|
|
579
579
|
},
|
|
580
|
-
"__@toStringTag@
|
|
580
|
+
"__@toStringTag@75984": {
|
|
581
581
|
"type": "string"
|
|
582
582
|
}
|
|
583
583
|
},
|
|
584
584
|
"additionalProperties": false,
|
|
585
585
|
"required": [
|
|
586
|
-
"__@toStringTag@
|
|
586
|
+
"__@toStringTag@75984",
|
|
587
587
|
"byteLength"
|
|
588
588
|
]
|
|
589
589
|
},
|
|
@@ -593,18 +593,18 @@
|
|
|
593
593
|
"byteLength": {
|
|
594
594
|
"type": "number"
|
|
595
595
|
},
|
|
596
|
-
"__@species@
|
|
596
|
+
"__@species@76085": {
|
|
597
597
|
"$ref": "#/definitions/SharedArrayBuffer"
|
|
598
598
|
},
|
|
599
|
-
"__@toStringTag@
|
|
599
|
+
"__@toStringTag@75984": {
|
|
600
600
|
"type": "string",
|
|
601
601
|
"const": "SharedArrayBuffer"
|
|
602
602
|
}
|
|
603
603
|
},
|
|
604
604
|
"additionalProperties": false,
|
|
605
605
|
"required": [
|
|
606
|
-
"__@species@
|
|
607
|
-
"__@toStringTag@
|
|
606
|
+
"__@species@76085",
|
|
607
|
+
"__@toStringTag@75984",
|
|
608
608
|
"byteLength"
|
|
609
609
|
]
|
|
610
610
|
},
|
|
@@ -441,14 +441,14 @@
|
|
|
441
441
|
"length": {
|
|
442
442
|
"type": "number"
|
|
443
443
|
},
|
|
444
|
-
"__@toStringTag@
|
|
444
|
+
"__@toStringTag@108694": {
|
|
445
445
|
"type": "string",
|
|
446
446
|
"const": "Uint8Array"
|
|
447
447
|
}
|
|
448
448
|
},
|
|
449
449
|
"required": [
|
|
450
450
|
"BYTES_PER_ELEMENT",
|
|
451
|
-
"__@toStringTag@
|
|
451
|
+
"__@toStringTag@108694",
|
|
452
452
|
"buffer",
|
|
453
453
|
"byteLength",
|
|
454
454
|
"byteOffset",
|
|
@@ -483,13 +483,13 @@
|
|
|
483
483
|
"byteLength": {
|
|
484
484
|
"type": "number"
|
|
485
485
|
},
|
|
486
|
-
"__@toStringTag@
|
|
486
|
+
"__@toStringTag@108694": {
|
|
487
487
|
"type": "string"
|
|
488
488
|
}
|
|
489
489
|
},
|
|
490
490
|
"additionalProperties": false,
|
|
491
491
|
"required": [
|
|
492
|
-
"__@toStringTag@
|
|
492
|
+
"__@toStringTag@108694",
|
|
493
493
|
"byteLength"
|
|
494
494
|
]
|
|
495
495
|
},
|
|
@@ -499,18 +499,18 @@
|
|
|
499
499
|
"byteLength": {
|
|
500
500
|
"type": "number"
|
|
501
501
|
},
|
|
502
|
-
"__@species@
|
|
502
|
+
"__@species@108795": {
|
|
503
503
|
"$ref": "#/definitions/SharedArrayBuffer"
|
|
504
504
|
},
|
|
505
|
-
"__@toStringTag@
|
|
505
|
+
"__@toStringTag@108694": {
|
|
506
506
|
"type": "string",
|
|
507
507
|
"const": "SharedArrayBuffer"
|
|
508
508
|
}
|
|
509
509
|
},
|
|
510
510
|
"additionalProperties": false,
|
|
511
511
|
"required": [
|
|
512
|
-
"__@species@
|
|
513
|
-
"__@toStringTag@
|
|
512
|
+
"__@species@108795",
|
|
513
|
+
"__@toStringTag@108694",
|
|
514
514
|
"byteLength"
|
|
515
515
|
]
|
|
516
516
|
},
|
|
@@ -484,14 +484,14 @@
|
|
|
484
484
|
"length": {
|
|
485
485
|
"type": "number"
|
|
486
486
|
},
|
|
487
|
-
"__@toStringTag@
|
|
487
|
+
"__@toStringTag@119846": {
|
|
488
488
|
"type": "string",
|
|
489
489
|
"const": "Uint8Array"
|
|
490
490
|
}
|
|
491
491
|
},
|
|
492
492
|
"required": [
|
|
493
493
|
"BYTES_PER_ELEMENT",
|
|
494
|
-
"__@toStringTag@
|
|
494
|
+
"__@toStringTag@119846",
|
|
495
495
|
"buffer",
|
|
496
496
|
"byteLength",
|
|
497
497
|
"byteOffset",
|
|
@@ -526,13 +526,13 @@
|
|
|
526
526
|
"byteLength": {
|
|
527
527
|
"type": "number"
|
|
528
528
|
},
|
|
529
|
-
"__@toStringTag@
|
|
529
|
+
"__@toStringTag@119846": {
|
|
530
530
|
"type": "string"
|
|
531
531
|
}
|
|
532
532
|
},
|
|
533
533
|
"additionalProperties": false,
|
|
534
534
|
"required": [
|
|
535
|
-
"__@toStringTag@
|
|
535
|
+
"__@toStringTag@119846",
|
|
536
536
|
"byteLength"
|
|
537
537
|
]
|
|
538
538
|
},
|
|
@@ -542,18 +542,18 @@
|
|
|
542
542
|
"byteLength": {
|
|
543
543
|
"type": "number"
|
|
544
544
|
},
|
|
545
|
-
"__@species@
|
|
545
|
+
"__@species@119947": {
|
|
546
546
|
"$ref": "#/definitions/SharedArrayBuffer"
|
|
547
547
|
},
|
|
548
|
-
"__@toStringTag@
|
|
548
|
+
"__@toStringTag@119846": {
|
|
549
549
|
"type": "string",
|
|
550
550
|
"const": "SharedArrayBuffer"
|
|
551
551
|
}
|
|
552
552
|
},
|
|
553
553
|
"additionalProperties": false,
|
|
554
554
|
"required": [
|
|
555
|
-
"__@species@
|
|
556
|
-
"__@toStringTag@
|
|
555
|
+
"__@species@119947",
|
|
556
|
+
"__@toStringTag@119846",
|
|
557
557
|
"byteLength"
|
|
558
558
|
]
|
|
559
559
|
},
|
|
@@ -394,14 +394,14 @@
|
|
|
394
394
|
"length": {
|
|
395
395
|
"type": "number"
|
|
396
396
|
},
|
|
397
|
-
"__@toStringTag@
|
|
397
|
+
"__@toStringTag@130908": {
|
|
398
398
|
"type": "string",
|
|
399
399
|
"const": "Uint8Array"
|
|
400
400
|
}
|
|
401
401
|
},
|
|
402
402
|
"required": [
|
|
403
403
|
"BYTES_PER_ELEMENT",
|
|
404
|
-
"__@toStringTag@
|
|
404
|
+
"__@toStringTag@130908",
|
|
405
405
|
"buffer",
|
|
406
406
|
"byteLength",
|
|
407
407
|
"byteOffset",
|
|
@@ -436,13 +436,13 @@
|
|
|
436
436
|
"byteLength": {
|
|
437
437
|
"type": "number"
|
|
438
438
|
},
|
|
439
|
-
"__@toStringTag@
|
|
439
|
+
"__@toStringTag@130908": {
|
|
440
440
|
"type": "string"
|
|
441
441
|
}
|
|
442
442
|
},
|
|
443
443
|
"additionalProperties": false,
|
|
444
444
|
"required": [
|
|
445
|
-
"__@toStringTag@
|
|
445
|
+
"__@toStringTag@130908",
|
|
446
446
|
"byteLength"
|
|
447
447
|
]
|
|
448
448
|
},
|
|
@@ -452,18 +452,18 @@
|
|
|
452
452
|
"byteLength": {
|
|
453
453
|
"type": "number"
|
|
454
454
|
},
|
|
455
|
-
"__@species@
|
|
455
|
+
"__@species@131009": {
|
|
456
456
|
"$ref": "#/definitions/SharedArrayBuffer"
|
|
457
457
|
},
|
|
458
|
-
"__@toStringTag@
|
|
458
|
+
"__@toStringTag@130908": {
|
|
459
459
|
"type": "string",
|
|
460
460
|
"const": "SharedArrayBuffer"
|
|
461
461
|
}
|
|
462
462
|
},
|
|
463
463
|
"additionalProperties": false,
|
|
464
464
|
"required": [
|
|
465
|
-
"__@species@
|
|
466
|
-
"__@toStringTag@
|
|
465
|
+
"__@species@131009",
|
|
466
|
+
"__@toStringTag@130908",
|
|
467
467
|
"byteLength"
|
|
468
468
|
]
|
|
469
469
|
},
|
|
@@ -535,14 +535,14 @@
|
|
|
535
535
|
"length": {
|
|
536
536
|
"type": "number"
|
|
537
537
|
},
|
|
538
|
-
"__@toStringTag@
|
|
538
|
+
"__@toStringTag@217585": {
|
|
539
539
|
"type": "string",
|
|
540
540
|
"const": "Uint8Array"
|
|
541
541
|
}
|
|
542
542
|
},
|
|
543
543
|
"required": [
|
|
544
544
|
"BYTES_PER_ELEMENT",
|
|
545
|
-
"__@toStringTag@
|
|
545
|
+
"__@toStringTag@217585",
|
|
546
546
|
"buffer",
|
|
547
547
|
"byteLength",
|
|
548
548
|
"byteOffset",
|
|
@@ -577,13 +577,13 @@
|
|
|
577
577
|
"byteLength": {
|
|
578
578
|
"type": "number"
|
|
579
579
|
},
|
|
580
|
-
"__@toStringTag@
|
|
580
|
+
"__@toStringTag@217585": {
|
|
581
581
|
"type": "string"
|
|
582
582
|
}
|
|
583
583
|
},
|
|
584
584
|
"additionalProperties": false,
|
|
585
585
|
"required": [
|
|
586
|
-
"__@toStringTag@
|
|
586
|
+
"__@toStringTag@217585",
|
|
587
587
|
"byteLength"
|
|
588
588
|
]
|
|
589
589
|
},
|
|
@@ -593,18 +593,18 @@
|
|
|
593
593
|
"byteLength": {
|
|
594
594
|
"type": "number"
|
|
595
595
|
},
|
|
596
|
-
"__@species@
|
|
596
|
+
"__@species@217686": {
|
|
597
597
|
"$ref": "#/definitions/SharedArrayBuffer"
|
|
598
598
|
},
|
|
599
|
-
"__@toStringTag@
|
|
599
|
+
"__@toStringTag@217585": {
|
|
600
600
|
"type": "string",
|
|
601
601
|
"const": "SharedArrayBuffer"
|
|
602
602
|
}
|
|
603
603
|
},
|
|
604
604
|
"additionalProperties": false,
|
|
605
605
|
"required": [
|
|
606
|
-
"__@species@
|
|
607
|
-
"__@toStringTag@
|
|
606
|
+
"__@species@217686",
|
|
607
|
+
"__@toStringTag@217585",
|
|
608
608
|
"byteLength"
|
|
609
609
|
]
|
|
610
610
|
},
|
package/build/types.d.ts
CHANGED
|
@@ -9,12 +9,12 @@ import { HTTPRequest, Page, ResponseForRequest, ScreenshotOptions } from 'puppet
|
|
|
9
9
|
export type PathTypes = HTTPRoutes | WebsocketRoutes | HTTPManagementRoutes | string;
|
|
10
10
|
export interface BeforeRequest {
|
|
11
11
|
head?: Buffer;
|
|
12
|
-
req:
|
|
12
|
+
req: http.IncomingMessage;
|
|
13
13
|
res?: http.ServerResponse;
|
|
14
14
|
socket?: stream.Duplex;
|
|
15
15
|
}
|
|
16
16
|
export interface AfterResponse {
|
|
17
|
-
req:
|
|
17
|
+
req: Request;
|
|
18
18
|
start: number;
|
|
19
19
|
status: 'successful' | 'error' | 'timedout';
|
|
20
20
|
}
|
package/build/utils.js
CHANGED
|
@@ -322,15 +322,10 @@ export const availableBrowsers = Promise.all([
|
|
|
322
322
|
}
|
|
323
323
|
return availableBrowsers;
|
|
324
324
|
});
|
|
325
|
-
export const queryParamsToObject = (params) => {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
for (const [key, value] of entries) {
|
|
330
|
-
result[key] = value === '' ? true : jsonOrString(value);
|
|
331
|
-
}
|
|
332
|
-
return result;
|
|
333
|
-
};
|
|
325
|
+
export const queryParamsToObject = (params) => [...params.entries()].reduce((accum, [key, value]) => {
|
|
326
|
+
accum[key] = value;
|
|
327
|
+
return accum;
|
|
328
|
+
}, {});
|
|
334
329
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
335
330
|
const AsyncFunction = Object.getPrototypeOf(async function () { }).constructor;
|
|
336
331
|
const wrapUserFunction = (fn) => {
|
package/external/after.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default () =>
|
|
1
|
+
export default async () => {};
|
package/external/before.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default () => true;
|
|
1
|
+
export default async () => true;
|
package/external/browser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default () =>
|
|
1
|
+
export default async () => {};
|
package/external/page.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default () =>
|
|
1
|
+
export default async () => {};
|
package/package.json
CHANGED
package/src/browserless.ts
CHANGED
package/src/browsers/index.ts
CHANGED
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
noop,
|
|
31
31
|
parseBooleanParam,
|
|
32
32
|
} from '@browserless.io/browserless';
|
|
33
|
+
import { Page } from 'puppeteer-core';
|
|
33
34
|
import { deleteAsync } from 'del';
|
|
34
35
|
import path from 'path';
|
|
35
36
|
|
|
@@ -65,7 +66,7 @@ export class BrowserManager {
|
|
|
65
66
|
}
|
|
66
67
|
};
|
|
67
68
|
|
|
68
|
-
protected onNewPage = async (req: Request, page:
|
|
69
|
+
protected onNewPage = async (req: Request, page: Page) => {
|
|
69
70
|
await this.hooks.page({ meta: req.parsed, page });
|
|
70
71
|
};
|
|
71
72
|
|
package/src/hooks.ts
CHANGED
|
@@ -1,32 +1,50 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
|
+
AfterResponse,
|
|
3
|
+
BeforeRequest,
|
|
4
|
+
BrowserHook,
|
|
5
|
+
PageHook,
|
|
6
|
+
} from '@browserless.io/browserless';
|
|
2
7
|
import { EventEmitter } from 'events';
|
|
3
8
|
|
|
4
9
|
// KEPT for backwards compatibility reasons since some downstream
|
|
5
10
|
// docker images will override these files to inject their own hook
|
|
6
11
|
// behaviors
|
|
12
|
+
// @ts-ignore
|
|
7
13
|
import { default as afterRequest } from '../external/after.js';
|
|
14
|
+
// @ts-ignore
|
|
8
15
|
import { default as beforeRequest } from '../external/before.js';
|
|
16
|
+
// @ts-ignore
|
|
9
17
|
import { default as browserHook } from '../external/browser.js';
|
|
18
|
+
// @ts-ignore
|
|
10
19
|
import { default as pageHook } from '../external/page.js';
|
|
11
20
|
|
|
12
21
|
export class Hooks extends EventEmitter {
|
|
13
|
-
|
|
14
|
-
|
|
22
|
+
before(args: BeforeRequest): Promise<boolean> {
|
|
23
|
+
return beforeRequest(args);
|
|
15
24
|
}
|
|
16
25
|
|
|
17
|
-
|
|
18
|
-
return
|
|
26
|
+
after(args: AfterResponse): Promise<unknown> {
|
|
27
|
+
return afterRequest(args);
|
|
19
28
|
}
|
|
20
29
|
|
|
21
|
-
|
|
22
|
-
return
|
|
30
|
+
page(args: PageHook): Promise<unknown> {
|
|
31
|
+
return pageHook(args);
|
|
23
32
|
}
|
|
24
33
|
|
|
25
|
-
|
|
26
|
-
return
|
|
34
|
+
browser(args: BrowserHook): Promise<unknown> {
|
|
35
|
+
return browserHook(args);
|
|
27
36
|
}
|
|
28
37
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Implement any browserless-core-specific shutdown logic here.
|
|
40
|
+
* Calls the empty-SDK stop method for downstream implementations.
|
|
41
|
+
*/
|
|
42
|
+
public shutdown = async () => {
|
|
43
|
+
await this.stop();
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Left blank for downstream SDK modules to optionally implement.
|
|
48
|
+
*/
|
|
49
|
+
public stop = () => {};
|
|
32
50
|
}
|
package/src/types.ts
CHANGED
|
@@ -31,13 +31,13 @@ export type PathTypes =
|
|
|
31
31
|
|
|
32
32
|
export interface BeforeRequest {
|
|
33
33
|
head?: Buffer;
|
|
34
|
-
req:
|
|
34
|
+
req: http.IncomingMessage;
|
|
35
35
|
res?: http.ServerResponse;
|
|
36
36
|
socket?: stream.Duplex;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export interface AfterResponse {
|
|
40
|
-
req:
|
|
40
|
+
req: Request;
|
|
41
41
|
start: number;
|
|
42
42
|
status: 'successful' | 'error' | 'timedout';
|
|
43
43
|
}
|
package/src/utils.ts
CHANGED
|
@@ -463,16 +463,14 @@ export const availableBrowsers = Promise.all([
|
|
|
463
463
|
|
|
464
464
|
export const queryParamsToObject = (
|
|
465
465
|
params: URLSearchParams,
|
|
466
|
-
): Record<string, unknown> =>
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
return result;
|
|
475
|
-
};
|
|
466
|
+
): Record<string, unknown> =>
|
|
467
|
+
[...params.entries()].reduce(
|
|
468
|
+
(accum, [key, value]) => {
|
|
469
|
+
accum[key] = value;
|
|
470
|
+
return accum;
|
|
471
|
+
},
|
|
472
|
+
{} as Record<string, string>,
|
|
473
|
+
);
|
|
476
474
|
|
|
477
475
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
478
476
|
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
|
package/static/docs/swagger.json
CHANGED