@browserless.io/browserless 2.10.0 → 2.11.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.
Files changed (29) hide show
  1. package/CHANGELOG.md +6 -1
  2. package/build/browsers/chromium.cdp.d.ts +1 -0
  3. package/build/browsers/chromium.cdp.js +3 -0
  4. package/build/browsers/chromium.playwright.d.ts +1 -0
  5. package/build/browsers/chromium.playwright.js +3 -0
  6. package/build/browsers/firefox.playwright.d.ts +1 -0
  7. package/build/browsers/firefox.playwright.js +3 -0
  8. package/build/browsers/index.d.ts +0 -1
  9. package/build/browsers/index.js +3 -5
  10. package/build/browsers/webkit.playwright.d.ts +1 -0
  11. package/build/browsers/webkit.playwright.js +3 -0
  12. package/build/routes/chrome/http/pdf.post.body.json +8 -8
  13. package/build/routes/chrome/http/scrape.post.body.json +8 -8
  14. package/build/routes/chrome/http/screenshot.post.body.json +8 -8
  15. package/build/routes/chromium/http/content.post.body.json +8 -8
  16. package/build/routes/chromium/http/pdf.post.body.json +8 -8
  17. package/build/routes/chromium/http/scrape.post.body.json +8 -8
  18. package/build/routes/management/http/pressure.get.d.ts +47 -45
  19. package/build/routes/management/http/pressure.get.js +13 -11
  20. package/build/routes/management/http/pressure.get.response.json +74 -65
  21. package/package.json +1 -1
  22. package/src/browsers/chromium.cdp.ts +4 -0
  23. package/src/browsers/chromium.playwright.ts +4 -0
  24. package/src/browsers/firefox.playwright.ts +4 -0
  25. package/src/browsers/index.ts +3 -5
  26. package/src/browsers/webkit.playwright.ts +4 -0
  27. package/src/routes/management/http/pressure.get.ts +70 -66
  28. package/static/docs/swagger.json +76 -67
  29. package/static/docs/swagger.min.json +75 -66
@@ -1,76 +1,85 @@
1
1
  {
2
2
  "type": "object",
3
3
  "properties": {
4
- "cpu": {
5
- "description": "An integer representing the percentage of CPU being used. For instance 92 means 92%",
6
- "type": [
7
- "null",
8
- "number"
9
- ]
10
- },
11
- "date": {
12
- "description": "A number of milliseconds since epoch, or \"Date.now()\" equivalent.",
13
- "type": "number"
14
- },
15
- "isAvailable": {
16
- "description": "Whether or not a session can be connected and immediately ran on a health instance.",
17
- "type": "boolean"
18
- },
19
- "maxConcurrent": {
20
- "description": "The maximum amount of browsers that can be ran at a single time.",
21
- "type": "number"
22
- },
23
- "maxQueued": {
24
- "description": "The maximum amount of queued connections allowed at a single time.",
25
- "type": "number"
26
- },
27
- "memory": {
28
- "description": "An integer representing the percentage of Memory being used. For instance 95 means 95%",
29
- "type": [
30
- "null",
31
- "number"
32
- ]
33
- },
34
- "message": {
35
- "description": "A human-readable message as the overall status of the instance.",
36
- "type": "string"
37
- },
38
- "queued": {
39
- "description": "The current number of connect or API calls pending to run.",
40
- "type": "number"
41
- },
42
- "reason": {
43
- "description": "A simple single-word reason as to why an instance may or may not be available.",
44
- "enum": [
45
- "",
4
+ "pressure": {
5
+ "type": "object",
6
+ "properties": {
7
+ "cpu": {
8
+ "description": "An integer representing the percentage of CPU being used. For instance 92 means 92%",
9
+ "type": [
10
+ "null",
11
+ "number"
12
+ ]
13
+ },
14
+ "date": {
15
+ "description": "A number of milliseconds since epoch, or \"Date.now()\" equivalent.",
16
+ "type": "number"
17
+ },
18
+ "isAvailable": {
19
+ "description": "Whether or not a session can be connected and immediately ran on a health instance.",
20
+ "type": "boolean"
21
+ },
22
+ "maxConcurrent": {
23
+ "description": "The maximum amount of browsers that can be ran at a single time.",
24
+ "type": "number"
25
+ },
26
+ "maxQueued": {
27
+ "description": "The maximum amount of queued connections allowed at a single time.",
28
+ "type": "number"
29
+ },
30
+ "memory": {
31
+ "description": "An integer representing the percentage of Memory being used. For instance 95 means 95%",
32
+ "type": [
33
+ "null",
34
+ "number"
35
+ ]
36
+ },
37
+ "message": {
38
+ "description": "A human-readable message as the overall status of the instance.",
39
+ "type": "string"
40
+ },
41
+ "queued": {
42
+ "description": "The current number of connect or API calls pending to run.",
43
+ "type": "number"
44
+ },
45
+ "reason": {
46
+ "description": "A simple single-word reason as to why an instance may or may not be available.",
47
+ "enum": [
48
+ "",
49
+ "cpu",
50
+ "full",
51
+ "memory"
52
+ ],
53
+ "type": "string"
54
+ },
55
+ "recentlyRejected": {
56
+ "description": "The number of recent connections that were rejected due to the queue and concurrency\nlimits having been filled.",
57
+ "type": "number"
58
+ },
59
+ "running": {
60
+ "description": "The current number of running connections or API calls.",
61
+ "type": "number"
62
+ }
63
+ },
64
+ "additionalProperties": false,
65
+ "required": [
46
66
  "cpu",
47
- "full",
48
- "memory"
49
- ],
50
- "type": "string"
51
- },
52
- "recentlyRejected": {
53
- "description": "The number of recent connections that were rejected due to the queue and concurrency\nlimits having been filled.",
54
- "type": "number"
55
- },
56
- "running": {
57
- "description": "The current number of running connections or API calls.",
58
- "type": "number"
67
+ "date",
68
+ "isAvailable",
69
+ "maxConcurrent",
70
+ "maxQueued",
71
+ "memory",
72
+ "message",
73
+ "queued",
74
+ "reason",
75
+ "recentlyRejected",
76
+ "running"
77
+ ]
59
78
  }
60
79
  },
61
80
  "additionalProperties": false,
62
81
  "required": [
63
- "cpu",
64
- "date",
65
- "isAvailable",
66
- "maxConcurrent",
67
- "maxQueued",
68
- "memory",
69
- "message",
70
- "queued",
71
- "reason",
72
- "recentlyRejected",
73
- "running"
82
+ "pressure"
74
83
  ],
75
84
  "$schema": "http://json-schema.org/draft-07/schema#"
76
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@browserless.io/browserless",
3
- "version": "2.10.0",
3
+ "version": "2.11.0",
4
4
  "license": "SSPL",
5
5
  "description": "The browserless platform",
6
6
  "author": "browserless.io",
@@ -59,6 +59,10 @@ export class ChromiumCDP extends EventEmitter {
59
59
  this.removeAllListeners();
60
60
  }
61
61
 
62
+ public keepAlive() {
63
+ return false;
64
+ }
65
+
62
66
  public getPageId = (page: Page): string => {
63
67
  // @ts-ignore
64
68
  return page.target()._targetId;
@@ -43,6 +43,10 @@ export class ChromiumPlaywright extends EventEmitter {
43
43
  this.removeAllListeners();
44
44
  }
45
45
 
46
+ public keepAlive() {
47
+ return false;
48
+ }
49
+
46
50
  public isRunning = (): boolean => this.running;
47
51
 
48
52
  public close = async (): Promise<void> => {
@@ -42,6 +42,10 @@ export class FirefoxPlaywright extends EventEmitter {
42
42
  this.removeAllListeners();
43
43
  }
44
44
 
45
+ public keepAlive() {
46
+ return false;
47
+ }
48
+
45
49
  public isRunning = (): boolean => this.running;
46
50
 
47
51
  public close = async (): Promise<void> => {
@@ -36,7 +36,6 @@ import path from 'path';
36
36
 
37
37
  export class BrowserManager {
38
38
  protected browsers: Map<BrowserInstance, BrowserlessSession> = new Map();
39
- protected launching: Map<string, Promise<unknown>> = new Map();
40
39
  protected timers: Map<string, number> = new Map();
41
40
  protected log = new Logger('browser-manager');
42
41
  protected chromeBrowsers = [ChromiumCDP, ChromeCDP];
@@ -272,7 +271,7 @@ export class BrowserManager {
272
271
  this.log.info(`${session.numbConnected} Client(s) are currently connected`);
273
272
 
274
273
  // Don't close if there's clients still connected
275
- if (session.numbConnected > 0) {
274
+ if (session.numbConnected > 0 || browser.keepAlive()) {
276
275
  return;
277
276
  }
278
277
 
@@ -314,7 +313,6 @@ export class BrowserManager {
314
313
 
315
314
  if (id && resolver) {
316
315
  resolver(null);
317
- this.launching.delete(id);
318
316
  }
319
317
 
320
318
  --session.numbConnected;
@@ -457,7 +455,7 @@ export class BrowserManager {
457
455
  userDataDir,
458
456
  });
459
457
 
460
- const connectionMeta: BrowserlessSession = {
458
+ const session: BrowserlessSession = {
461
459
  id: null,
462
460
  initialConnectURL:
463
461
  path.join(req.parsed.pathname, req.parsed.search) || '',
@@ -471,7 +469,7 @@ export class BrowserManager {
471
469
  userDataDir,
472
470
  };
473
471
 
474
- this.browsers.set(browser, connectionMeta);
472
+ this.browsers.set(browser, session);
475
473
 
476
474
  await browser.launch(launchOptions as object);
477
475
  await this.hooks.browser({ browser, meta: req.parsed });
@@ -42,6 +42,10 @@ export class WebkitPlaywright extends EventEmitter {
42
42
  this.removeAllListeners();
43
43
  }
44
44
 
45
+ public keepAlive() {
46
+ return false;
47
+ }
48
+
45
49
  public isRunning = (): boolean => this.running;
46
50
 
47
51
  public close = async (): Promise<void> => {
@@ -11,61 +11,63 @@ import {
11
11
  import { ServerResponse } from 'http';
12
12
 
13
13
  export type ResponseSchema = {
14
- /**
15
- * An integer representing the percentage of CPU being used. For instance 92 means 92%
16
- */
17
- cpu: number | null;
18
-
19
- /**
20
- * A number of milliseconds since epoch, or "Date.now()" equivalent.
21
- */
22
- date: number;
23
-
24
- /**
25
- * Whether or not a session can be connected and immediately ran on a health instance.
26
- */
27
- isAvailable: boolean;
28
-
29
- /**
30
- * The maximum amount of browsers that can be ran at a single time.
31
- */
32
- maxConcurrent: number;
33
-
34
- /**
35
- * The maximum amount of queued connections allowed at a single time.
36
- */
37
- maxQueued: number;
38
-
39
- /**
40
- * An integer representing the percentage of Memory being used. For instance 95 means 95%
41
- */
42
- memory: number | null;
43
-
44
- /**
45
- * A human-readable message as the overall status of the instance.
46
- */
47
- message: string;
48
-
49
- /**
50
- * The current number of connect or API calls pending to run.
51
- */
52
- queued: number;
53
-
54
- /**
55
- * A simple single-word reason as to why an instance may or may not be available.
56
- */
57
- reason: 'full' | 'cpu' | 'memory' | '';
58
-
59
- /**
60
- * The number of recent connections that were rejected due to the queue and concurrency
61
- * limits having been filled.
62
- */
63
- recentlyRejected: number;
64
-
65
- /**
66
- * The current number of running connections or API calls.
67
- */
68
- running: number;
14
+ pressure: {
15
+ /**
16
+ * An integer representing the percentage of CPU being used. For instance 92 means 92%
17
+ */
18
+ cpu: number | null;
19
+
20
+ /**
21
+ * A number of milliseconds since epoch, or "Date.now()" equivalent.
22
+ */
23
+ date: number;
24
+
25
+ /**
26
+ * Whether or not a session can be connected and immediately ran on a health instance.
27
+ */
28
+ isAvailable: boolean;
29
+
30
+ /**
31
+ * The maximum amount of browsers that can be ran at a single time.
32
+ */
33
+ maxConcurrent: number;
34
+
35
+ /**
36
+ * The maximum amount of queued connections allowed at a single time.
37
+ */
38
+ maxQueued: number;
39
+
40
+ /**
41
+ * An integer representing the percentage of Memory being used. For instance 95 means 95%
42
+ */
43
+ memory: number | null;
44
+
45
+ /**
46
+ * A human-readable message as the overall status of the instance.
47
+ */
48
+ message: string;
49
+
50
+ /**
51
+ * The current number of connect or API calls pending to run.
52
+ */
53
+ queued: number;
54
+
55
+ /**
56
+ * A simple single-word reason as to why an instance may or may not be available.
57
+ */
58
+ reason: 'full' | 'cpu' | 'memory' | '';
59
+
60
+ /**
61
+ * The number of recent connections that were rejected due to the queue and concurrency
62
+ * limits having been filled.
63
+ */
64
+ recentlyRejected: number;
65
+
66
+ /**
67
+ * The current number of running connections or API calls.
68
+ */
69
+ running: number;
70
+ };
69
71
  };
70
72
 
71
73
  export default class PressureGetRoute extends HTTPRoute {
@@ -117,17 +119,19 @@ export default class PressureGetRoute extends HTTPRoute {
117
119
  : '';
118
120
 
119
121
  const response: ResponseSchema = {
120
- cpu,
121
- date,
122
- isAvailable,
123
- maxConcurrent,
124
- maxQueued,
125
- memory,
126
- message,
127
- queued,
128
- reason,
129
- recentlyRejected,
130
- running,
122
+ pressure: {
123
+ cpu,
124
+ date,
125
+ isAvailable,
126
+ maxConcurrent,
127
+ maxQueued,
128
+ memory,
129
+ message,
130
+ queued,
131
+ reason,
132
+ recentlyRejected,
133
+ running,
134
+ },
131
135
  };
132
136
 
133
137
  return jsonResponse(res, 200, response);