@browserless.io/browserless 2.12.0-beta-4 → 2.12.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 (146) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/bin/scaffold/README.md +6 -5
  3. package/bin/scaffold/src/hello-world.http.ts +3 -3
  4. package/build/browserless.d.ts +3 -3
  5. package/build/browserless.js +6 -6
  6. package/build/browsers/chromium.cdp.d.ts +12 -12
  7. package/build/browsers/chromium.cdp.js +77 -65
  8. package/build/browsers/chromium.playwright.d.ts +11 -11
  9. package/build/browsers/chromium.playwright.js +42 -34
  10. package/build/browsers/firefox.playwright.d.ts +11 -11
  11. package/build/browsers/firefox.playwright.js +42 -34
  12. package/build/browsers/index.d.ts +14 -14
  13. package/build/browsers/index.js +27 -25
  14. package/build/browsers/webkit.playwright.d.ts +11 -11
  15. package/build/browsers/webkit.playwright.js +43 -35
  16. package/build/config.d.ts +65 -63
  17. package/build/config.js +162 -102
  18. package/build/file-system.d.ts +4 -4
  19. package/build/file-system.js +8 -8
  20. package/build/hooks.d.ts +2 -2
  21. package/build/hooks.js +4 -4
  22. package/build/limiter.d.ts +4 -4
  23. package/build/limiter.js +10 -10
  24. package/build/logger.d.ts +6 -6
  25. package/build/logger.js +12 -12
  26. package/build/metrics.d.ts +12 -12
  27. package/build/metrics.js +23 -23
  28. package/build/monitoring.d.ts +4 -4
  29. package/build/monitoring.js +8 -8
  30. package/build/router.d.ts +8 -8
  31. package/build/router.js +74 -70
  32. package/build/routes/chrome/http/pdf.post.body.json +8 -8
  33. package/build/routes/chrome/http/scrape.post.body.json +8 -8
  34. package/build/routes/chrome/http/screenshot.post.body.json +8 -8
  35. package/build/routes/chromium/http/content.post.body.json +8 -8
  36. package/build/routes/chromium/http/pdf.post.body.json +8 -8
  37. package/build/routes/chromium/http/scrape.post.body.json +8 -8
  38. package/build/routes/chromium/http/screenshot.post.body.json +8 -8
  39. package/build/routes/firefox/ws/playwright.d.ts +1 -1
  40. package/build/routes/firefox/ws/playwright.js +2 -2
  41. package/build/routes/management/http/active.get.d.ts +1 -1
  42. package/build/routes/management/http/active.get.js +3 -1
  43. package/build/routes/management/http/config.get.d.ts +1 -1
  44. package/build/routes/management/http/config.get.js +2 -2
  45. package/build/routes/management/http/metrics-total.get.d.ts +1 -1
  46. package/build/routes/management/http/metrics-total.get.js +2 -2
  47. package/build/routes/management/http/metrics.get.d.ts +1 -1
  48. package/build/routes/management/http/metrics.get.js +2 -2
  49. package/build/routes/management/http/pressure.get.d.ts +1 -1
  50. package/build/routes/management/http/pressure.get.js +2 -2
  51. package/build/routes/management/http/sessions.get.d.ts +1 -1
  52. package/build/routes/management/http/sessions.get.js +2 -2
  53. package/build/routes/management/http/static.get.d.ts +1 -1
  54. package/build/routes/management/http/static.get.js +2 -2
  55. package/build/routes/webkit/ws/playwright.d.ts +1 -1
  56. package/build/routes/webkit/ws/playwright.js +2 -2
  57. package/build/server.d.ts +5 -5
  58. package/build/server.js +11 -11
  59. package/build/shared/browser.ws.d.ts +1 -1
  60. package/build/shared/browser.ws.js +3 -1
  61. package/build/shared/chromium.playwright.ws.d.ts +1 -1
  62. package/build/shared/chromium.playwright.ws.js +2 -2
  63. package/build/shared/chromium.ws.d.ts +1 -1
  64. package/build/shared/chromium.ws.js +3 -1
  65. package/build/shared/content.http.d.ts +1 -1
  66. package/build/shared/content.http.js +2 -2
  67. package/build/shared/download.http.d.ts +1 -1
  68. package/build/shared/download.http.js +60 -58
  69. package/build/shared/function.http.d.ts +1 -1
  70. package/build/shared/function.http.js +2 -2
  71. package/build/shared/json-list.http.d.ts +1 -1
  72. package/build/shared/json-list.http.js +2 -2
  73. package/build/shared/json-new.http.d.ts +1 -1
  74. package/build/shared/json-new.http.js +2 -2
  75. package/build/shared/json-protocol.http.d.ts +1 -1
  76. package/build/shared/json-protocol.http.js +2 -2
  77. package/build/shared/json-version.http.d.ts +1 -1
  78. package/build/shared/json-version.http.js +2 -2
  79. package/build/shared/page.ws.d.ts +1 -1
  80. package/build/shared/page.ws.js +3 -1
  81. package/build/shared/pdf.http.d.ts +1 -1
  82. package/build/shared/pdf.http.js +2 -2
  83. package/build/shared/performance.http.d.ts +1 -1
  84. package/build/shared/performance.http.js +2 -2
  85. package/build/shared/scrape.http.d.ts +1 -1
  86. package/build/shared/scrape.http.js +2 -2
  87. package/build/shared/screenshot.http.d.ts +1 -1
  88. package/build/shared/screenshot.http.js +2 -2
  89. package/build/shared/utils/function/client.d.ts +1 -1
  90. package/build/shared/utils/function/client.js +3 -1
  91. package/build/shim.d.ts +1 -1
  92. package/build/shim.js +2 -2
  93. package/build/token.d.ts +3 -3
  94. package/build/token.js +6 -6
  95. package/build/types.d.ts +4 -4
  96. package/build/webhooks.d.ts +2 -2
  97. package/build/webhooks.js +4 -4
  98. package/package.json +3 -3
  99. package/src/browserless.ts +6 -6
  100. package/src/browsers/chromium.cdp.ts +33 -23
  101. package/src/browsers/chromium.playwright.ts +28 -21
  102. package/src/browsers/firefox.playwright.ts +28 -21
  103. package/src/browsers/index.ts +32 -29
  104. package/src/browsers/webkit.playwright.ts +29 -22
  105. package/src/config.ts +166 -104
  106. package/src/file-system.ts +9 -9
  107. package/src/hooks.ts +4 -4
  108. package/src/limiter.ts +12 -12
  109. package/src/logger.ts +12 -12
  110. package/src/metrics.ts +23 -23
  111. package/src/monitoring.ts +9 -9
  112. package/src/router.ts +31 -31
  113. package/src/routes/firefox/ws/playwright.ts +3 -3
  114. package/src/routes/management/http/active.get.ts +3 -2
  115. package/src/routes/management/http/config.get.ts +2 -2
  116. package/src/routes/management/http/metrics-total.get.ts +2 -2
  117. package/src/routes/management/http/metrics.get.ts +2 -2
  118. package/src/routes/management/http/pressure.get.ts +2 -2
  119. package/src/routes/management/http/sessions.get.ts +2 -2
  120. package/src/routes/management/http/static.get.ts +3 -3
  121. package/src/routes/webkit/ws/playwright.ts +3 -3
  122. package/src/server.ts +14 -16
  123. package/src/shared/browser.ws.ts +4 -2
  124. package/src/shared/chromium.playwright.ws.ts +3 -3
  125. package/src/shared/chromium.ws.ts +4 -2
  126. package/src/shared/content.http.ts +3 -3
  127. package/src/shared/download.http.ts +4 -3
  128. package/src/shared/function.http.ts +3 -3
  129. package/src/shared/json-list.http.ts +2 -2
  130. package/src/shared/json-new.http.ts +2 -2
  131. package/src/shared/json-protocol.http.ts +2 -6
  132. package/src/shared/json-version.http.ts +2 -6
  133. package/src/shared/page.ws.ts +4 -2
  134. package/src/shared/pdf.http.ts +3 -3
  135. package/src/shared/performance.http.ts +3 -3
  136. package/src/shared/scrape.http.ts +3 -3
  137. package/src/shared/screenshot.http.ts +3 -3
  138. package/src/shared/utils/function/client.ts +3 -1
  139. package/src/shim.ts +2 -2
  140. package/src/token.ts +7 -7
  141. package/src/types.ts +7 -7
  142. package/src/webhooks.ts +4 -4
  143. package/static/docs/swagger.json +2 -2
  144. package/static/docs/swagger.min.json +1 -1
  145. package/static/function/client.js +3 -1
  146. package/static/function/index.html +3 -1
@@ -27,11 +27,7 @@ export default class ChromiumJSONProtocolGetRoute extends HTTPRoute {
27
27
  path = HTTPRoutes.jsonProtocol;
28
28
  tags = [APITags.browserAPI];
29
29
 
30
- handler = async (
31
- _req: Request,
32
- res: Response,
33
- logger: Logger,
34
- ): Promise<void> => {
30
+ async handler(_req: Request, res: Response, logger: Logger): Promise<void> {
35
31
  const browserManager = this.browserManager();
36
32
 
37
33
  if (!this.cachedProtocol) {
@@ -39,5 +35,5 @@ export default class ChromiumJSONProtocolGetRoute extends HTTPRoute {
39
35
  }
40
36
 
41
37
  return jsonResponse(res, 200, this.cachedProtocol);
42
- };
38
+ }
43
39
  }
@@ -31,11 +31,7 @@ export default class ChromiumJSONVersionGetRoute extends HTTPRoute {
31
31
  method = Methods.get;
32
32
  path = HTTPRoutes.jsonVersion;
33
33
  tags = [APITags.browserAPI];
34
- handler = async (
35
- req: Request,
36
- res: Response,
37
- logger: Logger,
38
- ): Promise<void> => {
34
+ async handler(req: Request, res: Response, logger: Logger): Promise<void> {
39
35
  const baseUrl = req.parsed.host;
40
36
  const protocol = req.parsed.protocol.includes('s') ? 'wss' : 'ws';
41
37
 
@@ -56,5 +52,5 @@ export default class ChromiumJSONVersionGetRoute extends HTTPRoute {
56
52
  contentTypes.text,
57
53
  );
58
54
  }
59
- };
55
+ }
60
56
  }
@@ -29,11 +29,13 @@ export default class ChromiumPageWebSocketRoute extends BrowserWebsocketRoute {
29
29
  );
30
30
  path = WebsocketRoutes.page;
31
31
  tags = [APITags.browserWS];
32
- handler = async (
32
+ async handler(
33
33
  req: Request,
34
34
  socket: Duplex,
35
35
  head: Buffer,
36
36
  _logger: Logger,
37
37
  browser: ChromiumCDP,
38
- ): Promise<void> => browser.proxyPageWebSocket(req, socket, head);
38
+ ): Promise<void> {
39
+ return browser.proxyPageWebSocket(req, socket, head);
40
+ }
39
41
  }
@@ -80,12 +80,12 @@ export default class ChromiumPDFPostRoute extends BrowserHTTPRoute {
80
80
  method = Methods.post;
81
81
  path = [HTTPRoutes.pdf, HTTPRoutes.chromiumPdf];
82
82
  tags = [APITags.browserAPI];
83
- handler = async (
83
+ async handler(
84
84
  req: Request,
85
85
  res: ServerResponse,
86
86
  logger: Logger,
87
87
  browser: BrowserInstance,
88
- ): Promise<void> => {
88
+ ): Promise<void> {
89
89
  logger.info('PDF API invoked with body:', req.body);
90
90
  const contentType =
91
91
  !req.headers.accept || req.headers.accept?.includes('*')
@@ -246,5 +246,5 @@ export default class ChromiumPDFPostRoute extends BrowserHTTPRoute {
246
246
  page.close().catch(noop);
247
247
 
248
248
  logger.info('PDF API request completed');
249
- };
249
+ }
250
250
  }
@@ -45,12 +45,12 @@ export default class PerformancePost extends BrowserHTTPRoute {
45
45
  method = Methods.post;
46
46
  path = [HTTPRoutes.performance, HTTPRoutes.chromiumPerformance];
47
47
  tags = [APITags.browserAPI];
48
- handler = async (
48
+ async handler(
49
49
  req: Request,
50
50
  res: ServerResponse,
51
51
  _logger: Logger,
52
52
  browser: BrowserInstance,
53
- ): Promise<void> => {
53
+ ): Promise<void> {
54
54
  const config = this.config();
55
55
  const response = await main({
56
56
  browser,
@@ -60,5 +60,5 @@ export default class PerformancePost extends BrowserHTTPRoute {
60
60
  });
61
61
 
62
62
  return jsonResponse(res, 200, response);
63
- };
63
+ }
64
64
  }
@@ -216,12 +216,12 @@ export default class ChromiumScrapePostRoute extends BrowserHTTPRoute {
216
216
  method = Methods.post;
217
217
  path = [HTTPRoutes.scrape, HTTPRoutes.chromiumScrape];
218
218
  tags = [APITags.browserAPI];
219
- handler = async (
219
+ async handler(
220
220
  req: Request,
221
221
  res: ServerResponse,
222
222
  logger: Logger,
223
223
  browser: BrowserInstance,
224
- ) => {
224
+ ) {
225
225
  logger.info('Scrape API invoked with body:', req.body);
226
226
  const contentType =
227
227
  !req.headers.accept || req.headers.accept?.includes('*')
@@ -440,5 +440,5 @@ export default class ChromiumScrapePostRoute extends BrowserHTTPRoute {
440
440
  logger.info('Scrape API request completed');
441
441
 
442
442
  return jsonResponse(res, 200, response, false);
443
- };
443
+ }
444
444
  }
@@ -83,12 +83,12 @@ export default class ScreenshotPost extends BrowserHTTPRoute {
83
83
  method = Methods.post;
84
84
  path = [HTTPRoutes.screenshot, HTTPRoutes.chromiumScreenshot];
85
85
  tags = [APITags.browserAPI];
86
- handler = async (
86
+ async handler(
87
87
  req: Request,
88
88
  res: ServerResponse,
89
89
  logger: Logger,
90
90
  browser: BrowserInstance,
91
- ): Promise<void> => {
91
+ ): Promise<void> {
92
92
  logger.info('Screenshot API invoked with body:', req.body);
93
93
  const contentType =
94
94
  !req.headers.accept || req.headers.accept?.includes('*')
@@ -267,5 +267,5 @@ export default class ScreenshotPost extends BrowserHTTPRoute {
267
267
 
268
268
  page.close().catch(noop);
269
269
  logger.info('Screenshot API request completed');
270
- };
270
+ }
271
271
  }
@@ -11,7 +11,9 @@ export class FunctionRunner {
11
11
  protected browser?: Browser;
12
12
  protected page?: Page;
13
13
 
14
- public log = () => console.log.bind(console);
14
+ public log() {
15
+ return console.log.bind(console);
16
+ }
15
17
 
16
18
  public async start(data: {
17
19
  browserWSEndpoint: string;
package/src/shim.ts CHANGED
@@ -14,7 +14,7 @@ const shimParam = ['headless', 'stealth', 'ignoreDefaultArgs', 'slowMo'];
14
14
  *
15
15
  * @param req A parsed user requests
16
16
  */
17
- export const shimLegacyRequests = (url: URL): URL => {
17
+ export function shimLegacyRequests(url: URL): URL {
18
18
  const { searchParams } = url;
19
19
  const params = [...searchParams];
20
20
  const names = params.map(([k]) => k);
@@ -76,4 +76,4 @@ export const shimLegacyRequests = (url: URL): URL => {
76
76
  }
77
77
 
78
78
  return url;
79
- };
79
+ }
package/src/token.ts CHANGED
@@ -14,14 +14,14 @@ export class Token extends EventEmitter {
14
14
  super();
15
15
  }
16
16
 
17
- public isAuthorized = async (
17
+ public async isAuthorized(
18
18
  req: Request,
19
19
  route:
20
20
  | BrowserHTTPRoute
21
21
  | BrowserWebsocketRoute
22
22
  | HTTPRoute
23
23
  | WebSocketRoute,
24
- ): Promise<boolean> => {
24
+ ): Promise<boolean> {
25
25
  const token = this.config.getToken();
26
26
 
27
27
  if (token === null) {
@@ -39,18 +39,18 @@ export class Token extends EventEmitter {
39
39
  }
40
40
 
41
41
  return (Array.isArray(token) ? token : [token]).includes(requestToken);
42
- };
42
+ }
43
43
 
44
44
  /**
45
45
  * Implement any browserless-core-specific shutdown logic here.
46
46
  * Calls the empty-SDK stop method for downstream implementations.
47
47
  */
48
- public shutdown = async () => {
49
- await this.stop();
50
- };
48
+ public async shutdown() {
49
+ return await this.stop();
50
+ }
51
51
 
52
52
  /**
53
53
  * Left blank for downstream SDK modules to optionally implement.
54
54
  */
55
- public stop = () => {};
55
+ public stop() {}
56
56
  }
package/src/types.ts CHANGED
@@ -251,11 +251,11 @@ export abstract class HTTPRoute extends BasicHTTPRoute {
251
251
  /**
252
252
  * Handles an inbound HTTP request, and supplies the Request and Response objects from node's HTTP request event
253
253
  */
254
- abstract handler: (
254
+ abstract handler(
255
255
  req: Request,
256
256
  res: http.ServerResponse,
257
257
  logger: Logger,
258
- ) => Promise<unknown>;
258
+ ): Promise<unknown>;
259
259
  }
260
260
 
261
261
  /**
@@ -272,12 +272,12 @@ export abstract class BrowserHTTPRoute extends BasicHTTPRoute {
272
272
  * Handles an inbound HTTP request with a 3rd param of the predefined
273
273
  * browser used for the route -- only Chrome CDP is support currently.
274
274
  */
275
- abstract handler: (
275
+ abstract handler(
276
276
  req: Request,
277
277
  res: http.ServerResponse,
278
278
  logger: Logger,
279
279
  browser: BrowserInstance,
280
- ) => Promise<unknown>;
280
+ ): Promise<unknown>;
281
281
 
282
282
  /**
283
283
  * An optional function to automatically set up or handle new page
@@ -296,12 +296,12 @@ export abstract class WebSocketRoute extends Route {
296
296
  /**
297
297
  * Handles an inbound Websocket request, and handles the connection
298
298
  */
299
- abstract handler: (
299
+ abstract handler(
300
300
  req: Request,
301
301
  socket: stream.Duplex,
302
302
  head: Buffer,
303
303
  logger: Logger,
304
- ) => Promise<unknown>;
304
+ ): Promise<unknown>;
305
305
  }
306
306
 
307
307
  /**
@@ -382,7 +382,7 @@ export interface BrowserlessSession {
382
382
  isTempDataDir: boolean;
383
383
  launchOptions: CDPLaunchOptions | BrowserServerOptions;
384
384
  numbConnected: number;
385
- resolver: (val: unknown) => void;
385
+ resolver(val: unknown): void;
386
386
  routePath: string | string[];
387
387
  startedOn: number;
388
388
  ttl: number;
package/src/webhooks.ts CHANGED
@@ -55,12 +55,12 @@ export class WebHooks extends EventEmitter {
55
55
  * Implement any browserless-core-specific shutdown logic here.
56
56
  * Calls the empty-SDK stop method for downstream implementations.
57
57
  */
58
- public shutdown = async () => {
59
- await this.stop();
60
- };
58
+ public async shutdown() {
59
+ return await this.stop();
60
+ }
61
61
 
62
62
  /**
63
63
  * Left blank for downstream SDK modules to optionally implement.
64
64
  */
65
- public stop = () => {};
65
+ public stop() {}
66
66
  }