@browserless.io/browserless 2.9.0 → 2.10.0

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/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
- # [Latest](https://github.com/browserless/chrome/compare/v2.9.0...main)
1
+ # [Latest](https://github.com/browserless/chrome/compare/v2.10.0...main)
2
+ - Dependency updates.
3
+
4
+ # [v2.10.0](https://github.com/browserless/chrome/compare/v2.9.0...v2.10.0)
5
+ - Adds back in the `/pressure` API from V1.
2
6
  - Dependency updates.
3
7
 
4
8
  # [v2.9.0](https://github.com/browserless/chrome/compare/v2.8.0...v2.9.0)
@@ -147,11 +147,12 @@ export class Browserless extends EventEmitter {
147
147
  }));
148
148
  const routeImport = `${this.config.getIsWin() ? 'file:///' : ''}${httpRoute}`;
149
149
  const { default: Route, } = await import(routeImport + `?cb=${Date.now()}`);
150
- const route = new Route(this.browserManager, this.config, this.fileSystem, this.metrics, this.monitoring, this.staticSDKDir);
150
+ const route = new Route(this.browserManager, this.config, this.fileSystem, this.metrics, this.monitoring, this.staticSDKDir, this.limiter);
151
151
  if (!this.routeIsDisabled(route)) {
152
152
  route.bodySchema = safeParse(bodySchema);
153
153
  route.querySchema = safeParse(querySchema);
154
154
  route.config = () => this.config;
155
+ route.limiter = () => this.limiter;
155
156
  route.metrics = () => this.metrics;
156
157
  route.monitoring = () => this.monitoring;
157
158
  route.fileSystem = () => this.fileSystem;
@@ -173,10 +174,11 @@ export class Browserless extends EventEmitter {
173
174
  }));
174
175
  const wsImport = `${this.config.getIsWin() ? 'file:///' : ''}${wsRoute}`;
175
176
  const { default: Route, } = await import(wsImport + `?cb=${Date.now()}`);
176
- const route = new Route(this.browserManager, this.config, this.fileSystem, this.metrics, this.monitoring, this.staticSDKDir);
177
+ const route = new Route(this.browserManager, this.config, this.fileSystem, this.metrics, this.monitoring, this.staticSDKDir, this.limiter);
177
178
  if (!this.routeIsDisabled(route)) {
178
179
  route.querySchema = safeParse(querySchema);
179
180
  route.config = () => this.config;
181
+ route.limiter = () => this.limiter;
180
182
  route.metrics = () => this.metrics;
181
183
  route.monitoring = () => this.monitoring;
182
184
  route.fileSystem = () => this.fileSystem;
package/build/http.d.ts CHANGED
@@ -154,6 +154,7 @@ export declare enum HTTPManagementRoutes {
154
154
  config = "/config",
155
155
  metrics = "/metrics",
156
156
  metricsTotal = "/metrics/total",
157
+ pressure = "/pressure",
157
158
  sessions = "/sessions",
158
159
  static = "/"
159
160
  }
package/build/http.js CHANGED
@@ -119,6 +119,7 @@ export var HTTPManagementRoutes;
119
119
  HTTPManagementRoutes["config"] = "/config";
120
120
  HTTPManagementRoutes["metrics"] = "/metrics";
121
121
  HTTPManagementRoutes["metricsTotal"] = "/metrics/total";
122
+ HTTPManagementRoutes["pressure"] = "/pressure";
122
123
  HTTPManagementRoutes["sessions"] = "/sessions";
123
124
  HTTPManagementRoutes["static"] = "/";
124
125
  })(HTTPManagementRoutes || (HTTPManagementRoutes = {}));
@@ -394,14 +394,14 @@
394
394
  "length": {
395
395
  "type": "number"
396
396
  },
397
- "__@toStringTag@21862": {
397
+ "__@toStringTag@10986": {
398
398
  "type": "string",
399
399
  "const": "Uint8Array"
400
400
  }
401
401
  },
402
402
  "required": [
403
403
  "BYTES_PER_ELEMENT",
404
- "__@toStringTag@21862",
404
+ "__@toStringTag@10986",
405
405
  "buffer",
406
406
  "byteLength",
407
407
  "byteOffset",
@@ -436,13 +436,13 @@
436
436
  "byteLength": {
437
437
  "type": "number"
438
438
  },
439
- "__@toStringTag@21862": {
439
+ "__@toStringTag@10986": {
440
440
  "type": "string"
441
441
  }
442
442
  },
443
443
  "additionalProperties": false,
444
444
  "required": [
445
- "__@toStringTag@21862",
445
+ "__@toStringTag@10986",
446
446
  "byteLength"
447
447
  ]
448
448
  },
@@ -452,18 +452,18 @@
452
452
  "byteLength": {
453
453
  "type": "number"
454
454
  },
455
- "__@species@21963": {
455
+ "__@species@11087": {
456
456
  "$ref": "#/definitions/SharedArrayBuffer"
457
457
  },
458
- "__@toStringTag@21862": {
458
+ "__@toStringTag@10986": {
459
459
  "type": "string",
460
460
  "const": "SharedArrayBuffer"
461
461
  }
462
462
  },
463
463
  "additionalProperties": false,
464
464
  "required": [
465
- "__@species@21963",
466
- "__@toStringTag@21862",
465
+ "__@species@11087",
466
+ "__@toStringTag@10986",
467
467
  "byteLength"
468
468
  ]
469
469
  },
@@ -535,14 +535,14 @@
535
535
  "length": {
536
536
  "type": "number"
537
537
  },
538
- "__@toStringTag@76527": {
538
+ "__@toStringTag@65656": {
539
539
  "type": "string",
540
540
  "const": "Uint8Array"
541
541
  }
542
542
  },
543
543
  "required": [
544
544
  "BYTES_PER_ELEMENT",
545
- "__@toStringTag@76527",
545
+ "__@toStringTag@65656",
546
546
  "buffer",
547
547
  "byteLength",
548
548
  "byteOffset",
@@ -577,13 +577,13 @@
577
577
  "byteLength": {
578
578
  "type": "number"
579
579
  },
580
- "__@toStringTag@76527": {
580
+ "__@toStringTag@65656": {
581
581
  "type": "string"
582
582
  }
583
583
  },
584
584
  "additionalProperties": false,
585
585
  "required": [
586
- "__@toStringTag@76527",
586
+ "__@toStringTag@65656",
587
587
  "byteLength"
588
588
  ]
589
589
  },
@@ -593,18 +593,18 @@
593
593
  "byteLength": {
594
594
  "type": "number"
595
595
  },
596
- "__@species@76628": {
596
+ "__@species@65757": {
597
597
  "$ref": "#/definitions/SharedArrayBuffer"
598
598
  },
599
- "__@toStringTag@76527": {
599
+ "__@toStringTag@65656": {
600
600
  "type": "string",
601
601
  "const": "SharedArrayBuffer"
602
602
  }
603
603
  },
604
604
  "additionalProperties": false,
605
605
  "required": [
606
- "__@species@76628",
607
- "__@toStringTag@76527",
606
+ "__@species@65757",
607
+ "__@toStringTag@65656",
608
608
  "byteLength"
609
609
  ]
610
610
  },
@@ -441,14 +441,14 @@
441
441
  "length": {
442
442
  "type": "number"
443
443
  },
444
- "__@toStringTag@98505": {
444
+ "__@toStringTag@87676": {
445
445
  "type": "string",
446
446
  "const": "Uint8Array"
447
447
  }
448
448
  },
449
449
  "required": [
450
450
  "BYTES_PER_ELEMENT",
451
- "__@toStringTag@98505",
451
+ "__@toStringTag@87676",
452
452
  "buffer",
453
453
  "byteLength",
454
454
  "byteOffset",
@@ -483,13 +483,13 @@
483
483
  "byteLength": {
484
484
  "type": "number"
485
485
  },
486
- "__@toStringTag@98505": {
486
+ "__@toStringTag@87676": {
487
487
  "type": "string"
488
488
  }
489
489
  },
490
490
  "additionalProperties": false,
491
491
  "required": [
492
- "__@toStringTag@98505",
492
+ "__@toStringTag@87676",
493
493
  "byteLength"
494
494
  ]
495
495
  },
@@ -499,18 +499,18 @@
499
499
  "byteLength": {
500
500
  "type": "number"
501
501
  },
502
- "__@species@98606": {
502
+ "__@species@87777": {
503
503
  "$ref": "#/definitions/SharedArrayBuffer"
504
504
  },
505
- "__@toStringTag@98505": {
505
+ "__@toStringTag@87676": {
506
506
  "type": "string",
507
507
  "const": "SharedArrayBuffer"
508
508
  }
509
509
  },
510
510
  "additionalProperties": false,
511
511
  "required": [
512
- "__@species@98606",
513
- "__@toStringTag@98505",
512
+ "__@species@87777",
513
+ "__@toStringTag@87676",
514
514
  "byteLength"
515
515
  ]
516
516
  },
@@ -484,14 +484,14 @@
484
484
  "length": {
485
485
  "type": "number"
486
486
  },
487
- "__@toStringTag@109724": {
487
+ "__@toStringTag@110043": {
488
488
  "type": "string",
489
489
  "const": "Uint8Array"
490
490
  }
491
491
  },
492
492
  "required": [
493
493
  "BYTES_PER_ELEMENT",
494
- "__@toStringTag@109724",
494
+ "__@toStringTag@110043",
495
495
  "buffer",
496
496
  "byteLength",
497
497
  "byteOffset",
@@ -526,13 +526,13 @@
526
526
  "byteLength": {
527
527
  "type": "number"
528
528
  },
529
- "__@toStringTag@109724": {
529
+ "__@toStringTag@110043": {
530
530
  "type": "string"
531
531
  }
532
532
  },
533
533
  "additionalProperties": false,
534
534
  "required": [
535
- "__@toStringTag@109724",
535
+ "__@toStringTag@110043",
536
536
  "byteLength"
537
537
  ]
538
538
  },
@@ -542,18 +542,18 @@
542
542
  "byteLength": {
543
543
  "type": "number"
544
544
  },
545
- "__@species@109825": {
545
+ "__@species@110144": {
546
546
  "$ref": "#/definitions/SharedArrayBuffer"
547
547
  },
548
- "__@toStringTag@109724": {
548
+ "__@toStringTag@110043": {
549
549
  "type": "string",
550
550
  "const": "SharedArrayBuffer"
551
551
  }
552
552
  },
553
553
  "additionalProperties": false,
554
554
  "required": [
555
- "__@species@109825",
556
- "__@toStringTag@109724",
555
+ "__@species@110144",
556
+ "__@toStringTag@110043",
557
557
  "byteLength"
558
558
  ]
559
559
  },
@@ -394,14 +394,14 @@
394
394
  "length": {
395
395
  "type": "number"
396
396
  },
397
- "__@toStringTag@120853": {
397
+ "__@toStringTag@98872": {
398
398
  "type": "string",
399
399
  "const": "Uint8Array"
400
400
  }
401
401
  },
402
402
  "required": [
403
403
  "BYTES_PER_ELEMENT",
404
- "__@toStringTag@120853",
404
+ "__@toStringTag@98872",
405
405
  "buffer",
406
406
  "byteLength",
407
407
  "byteOffset",
@@ -436,13 +436,13 @@
436
436
  "byteLength": {
437
437
  "type": "number"
438
438
  },
439
- "__@toStringTag@120853": {
439
+ "__@toStringTag@98872": {
440
440
  "type": "string"
441
441
  }
442
442
  },
443
443
  "additionalProperties": false,
444
444
  "required": [
445
- "__@toStringTag@120853",
445
+ "__@toStringTag@98872",
446
446
  "byteLength"
447
447
  ]
448
448
  },
@@ -452,18 +452,18 @@
452
452
  "byteLength": {
453
453
  "type": "number"
454
454
  },
455
- "__@species@120954": {
455
+ "__@species@98973": {
456
456
  "$ref": "#/definitions/SharedArrayBuffer"
457
457
  },
458
- "__@toStringTag@120853": {
458
+ "__@toStringTag@98872": {
459
459
  "type": "string",
460
460
  "const": "SharedArrayBuffer"
461
461
  }
462
462
  },
463
463
  "additionalProperties": false,
464
464
  "required": [
465
- "__@species@120954",
466
- "__@toStringTag@120853",
465
+ "__@species@98973",
466
+ "__@toStringTag@98872",
467
467
  "byteLength"
468
468
  ]
469
469
  },
@@ -535,14 +535,14 @@
535
535
  "length": {
536
536
  "type": "number"
537
537
  },
538
- "__@toStringTag@208086": {
538
+ "__@toStringTag@230185": {
539
539
  "type": "string",
540
540
  "const": "Uint8Array"
541
541
  }
542
542
  },
543
543
  "required": [
544
544
  "BYTES_PER_ELEMENT",
545
- "__@toStringTag@208086",
545
+ "__@toStringTag@230185",
546
546
  "buffer",
547
547
  "byteLength",
548
548
  "byteOffset",
@@ -577,13 +577,13 @@
577
577
  "byteLength": {
578
578
  "type": "number"
579
579
  },
580
- "__@toStringTag@208086": {
580
+ "__@toStringTag@230185": {
581
581
  "type": "string"
582
582
  }
583
583
  },
584
584
  "additionalProperties": false,
585
585
  "required": [
586
- "__@toStringTag@208086",
586
+ "__@toStringTag@230185",
587
587
  "byteLength"
588
588
  ]
589
589
  },
@@ -593,18 +593,18 @@
593
593
  "byteLength": {
594
594
  "type": "number"
595
595
  },
596
- "__@species@208187": {
596
+ "__@species@230286": {
597
597
  "$ref": "#/definitions/SharedArrayBuffer"
598
598
  },
599
- "__@toStringTag@208086": {
599
+ "__@toStringTag@230185": {
600
600
  "type": "string",
601
601
  "const": "SharedArrayBuffer"
602
602
  }
603
603
  },
604
604
  "additionalProperties": false,
605
605
  "required": [
606
- "__@species@208187",
607
- "__@toStringTag@208086",
606
+ "__@species@230286",
607
+ "__@toStringTag@230185",
608
608
  "byteLength"
609
609
  ]
610
610
  },
@@ -441,14 +441,14 @@
441
441
  "length": {
442
442
  "type": "number"
443
443
  },
444
- "__@toStringTag@230098": {
444
+ "__@toStringTag@208093": {
445
445
  "type": "string",
446
446
  "const": "Uint8Array"
447
447
  }
448
448
  },
449
449
  "required": [
450
450
  "BYTES_PER_ELEMENT",
451
- "__@toStringTag@230098",
451
+ "__@toStringTag@208093",
452
452
  "buffer",
453
453
  "byteLength",
454
454
  "byteOffset",
@@ -483,13 +483,13 @@
483
483
  "byteLength": {
484
484
  "type": "number"
485
485
  },
486
- "__@toStringTag@230098": {
486
+ "__@toStringTag@208093": {
487
487
  "type": "string"
488
488
  }
489
489
  },
490
490
  "additionalProperties": false,
491
491
  "required": [
492
- "__@toStringTag@230098",
492
+ "__@toStringTag@208093",
493
493
  "byteLength"
494
494
  ]
495
495
  },
@@ -499,18 +499,18 @@
499
499
  "byteLength": {
500
500
  "type": "number"
501
501
  },
502
- "__@species@230199": {
502
+ "__@species@208194": {
503
503
  "$ref": "#/definitions/SharedArrayBuffer"
504
504
  },
505
- "__@toStringTag@230098": {
505
+ "__@toStringTag@208093": {
506
506
  "type": "string",
507
507
  "const": "SharedArrayBuffer"
508
508
  }
509
509
  },
510
510
  "additionalProperties": false,
511
511
  "required": [
512
- "__@species@230199",
513
- "__@toStringTag@230098",
512
+ "__@species@208194",
513
+ "__@toStringTag@208093",
514
514
  "byteLength"
515
515
  ]
516
516
  },
@@ -484,14 +484,14 @@
484
484
  "length": {
485
485
  "type": "number"
486
486
  },
487
- "__@toStringTag@252176": {
487
+ "__@toStringTag@241336": {
488
488
  "type": "string",
489
489
  "const": "Uint8Array"
490
490
  }
491
491
  },
492
492
  "required": [
493
493
  "BYTES_PER_ELEMENT",
494
- "__@toStringTag@252176",
494
+ "__@toStringTag@241336",
495
495
  "buffer",
496
496
  "byteLength",
497
497
  "byteOffset",
@@ -526,13 +526,13 @@
526
526
  "byteLength": {
527
527
  "type": "number"
528
528
  },
529
- "__@toStringTag@252176": {
529
+ "__@toStringTag@241336": {
530
530
  "type": "string"
531
531
  }
532
532
  },
533
533
  "additionalProperties": false,
534
534
  "required": [
535
- "__@toStringTag@252176",
535
+ "__@toStringTag@241336",
536
536
  "byteLength"
537
537
  ]
538
538
  },
@@ -542,18 +542,18 @@
542
542
  "byteLength": {
543
543
  "type": "number"
544
544
  },
545
- "__@species@252277": {
545
+ "__@species@241437": {
546
546
  "$ref": "#/definitions/SharedArrayBuffer"
547
547
  },
548
- "__@toStringTag@252176": {
548
+ "__@toStringTag@241336": {
549
549
  "type": "string",
550
550
  "const": "SharedArrayBuffer"
551
551
  }
552
552
  },
553
553
  "additionalProperties": false,
554
554
  "required": [
555
- "__@species@252277",
556
- "__@toStringTag@252176",
555
+ "__@species@241437",
556
+ "__@toStringTag@241336",
557
557
  "byteLength"
558
558
  ]
559
559
  },
@@ -0,0 +1,63 @@
1
+ /// <reference types="node" />
2
+ import { APITags, HTTPManagementRoutes, HTTPRoute, Methods, Request, contentTypes } from '@browserless.io/browserless';
3
+ import { ServerResponse } from 'http';
4
+ export type ResponseSchema = {
5
+ /**
6
+ * An integer representing the percentage of CPU being used. For instance 92 means 92%
7
+ */
8
+ cpu: number | null;
9
+ /**
10
+ * A number of milliseconds since epoch, or "Date.now()" equivalent.
11
+ */
12
+ date: number;
13
+ /**
14
+ * Whether or not a session can be connected and immediately ran on a health instance.
15
+ */
16
+ isAvailable: boolean;
17
+ /**
18
+ * The maximum amount of browsers that can be ran at a single time.
19
+ */
20
+ maxConcurrent: number;
21
+ /**
22
+ * The maximum amount of queued connections allowed at a single time.
23
+ */
24
+ maxQueued: number;
25
+ /**
26
+ * An integer representing the percentage of Memory being used. For instance 95 means 95%
27
+ */
28
+ memory: number | null;
29
+ /**
30
+ * A human-readable message as the overall status of the instance.
31
+ */
32
+ message: string;
33
+ /**
34
+ * The current number of connect or API calls pending to run.
35
+ */
36
+ queued: number;
37
+ /**
38
+ * A simple single-word reason as to why an instance may or may not be available.
39
+ */
40
+ reason: 'full' | 'cpu' | 'memory' | '';
41
+ /**
42
+ * The number of recent connections that were rejected due to the queue and concurrency
43
+ * limits having been filled.
44
+ */
45
+ recentlyRejected: number;
46
+ /**
47
+ * The current number of running connections or API calls.
48
+ */
49
+ running: number;
50
+ };
51
+ export default class PressureGetRoute extends HTTPRoute {
52
+ name: string;
53
+ accepts: contentTypes[];
54
+ auth: boolean;
55
+ browser: null;
56
+ concurrency: boolean;
57
+ contentTypes: contentTypes[];
58
+ description: string;
59
+ method: Methods;
60
+ path: HTTPManagementRoutes;
61
+ tags: APITags[];
62
+ handler: (_req: Request, res: ServerResponse) => Promise<void>;
63
+ }
@@ -0,0 +1,56 @@
1
+ import { APITags, BrowserlessRoutes, HTTPManagementRoutes, HTTPRoute, Methods, contentTypes, jsonResponse, } from '@browserless.io/browserless';
2
+ export default class PressureGetRoute extends HTTPRoute {
3
+ name = BrowserlessRoutes.PressureGetRoute;
4
+ accepts = [contentTypes.any];
5
+ auth = true;
6
+ browser = null;
7
+ concurrency = false;
8
+ contentTypes = [contentTypes.json];
9
+ description = `Returns a JSON body of stats related to the pressure being created on the instance.`;
10
+ method = Methods.get;
11
+ path = HTTPManagementRoutes.pressure;
12
+ tags = [APITags.management];
13
+ handler = async (_req, res) => {
14
+ const monitoring = this.monitoring();
15
+ const config = this.config();
16
+ const limiter = this.limiter();
17
+ const metrics = this.metrics();
18
+ const { cpuInt: cpu, memoryInt: memory, cpuOverloaded, memoryOverloaded, } = await monitoring.overloaded();
19
+ const date = Date.now();
20
+ const hasCapacity = limiter.hasCapacity;
21
+ const queued = limiter.waiting;
22
+ const isAvailable = hasCapacity && !cpuOverloaded && !memoryOverloaded;
23
+ const running = limiter.executing;
24
+ const recentlyRejected = metrics.get().rejected;
25
+ const maxConcurrent = config.getConcurrent();
26
+ const maxQueued = config.getQueued();
27
+ const reason = !hasCapacity
28
+ ? 'full'
29
+ : cpuOverloaded
30
+ ? 'cpu'
31
+ : memoryOverloaded
32
+ ? 'memory'
33
+ : '';
34
+ const message = !hasCapacity
35
+ ? 'Concurrency and queue are full'
36
+ : cpuOverloaded
37
+ ? 'CPU is over the configured maximum for cpu percent'
38
+ : memoryOverloaded
39
+ ? 'Memory is over the configured maximum for memory percent'
40
+ : '';
41
+ const response = {
42
+ cpu,
43
+ date,
44
+ isAvailable,
45
+ maxConcurrent,
46
+ maxQueued,
47
+ memory,
48
+ message,
49
+ queued,
50
+ reason,
51
+ recentlyRejected,
52
+ running,
53
+ };
54
+ return jsonResponse(res, 200, response);
55
+ };
56
+ }