@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
package/src/config.ts CHANGED
@@ -168,55 +168,111 @@ export class Config extends EventEmitter {
168
168
  protected errorAlertURL = process.env.ERROR_ALERT_URL ?? null;
169
169
  protected pwVersions: { [key: string]: string } = {};
170
170
 
171
- public getRoutes = (): string => this.routes;
172
- public getHost = (): string => this.host;
173
- public getPort = (): number => this.port;
174
- public getIsWin = (): boolean => this.isWin;
175
- public getToken = (): string | null => this.token;
176
- public getDebug = (): string => this.debug;
177
- public getPwVersions = () => this.pwVersions;
171
+ public getRoutes(): string {
172
+ return this.routes;
173
+ }
174
+
175
+ public getHost(): string {
176
+ return this.host;
177
+ }
178
+
179
+ public getPort(): number {
180
+ return this.port;
181
+ }
182
+
183
+ public getIsWin(): boolean {
184
+ return this.isWin;
185
+ }
186
+
187
+ public getToken(): string | null {
188
+ return this.token;
189
+ }
190
+
191
+ public getDebug(): string {
192
+ return this.debug;
193
+ }
194
+
195
+ public getPwVersions() {
196
+ return this.pwVersions;
197
+ }
178
198
 
179
199
  /**
180
200
  * The maximum number of concurrent sessions allowed. Set
181
201
  * to "-1" or "Infinity" for no limit.
182
202
  * @returns number
183
203
  */
184
- public getConcurrent = (): number => this.concurrent;
204
+ public getConcurrent(): number {
205
+ return this.concurrent;
206
+ }
185
207
 
186
208
  /**
187
209
  * The maximum number of queued sessions allowed. Set to
188
210
  * "-1" or "Infinity" for no limit.
189
211
  * @returns number
190
212
  */
191
- public getQueued = (): number => this.queued;
192
- public getTimeout = (): number => this.timeout;
193
- public getStatic = (): string => this.static;
194
- public getDebuggerDir = (): string => this.debuggerDir;
195
- public getRetries = (): number => this.retries;
196
- public getAllowFileProtocol = (): boolean => this.allowFileProtocol;
197
- public getCPULimit = (): number => this.maxCpu;
198
- public getMemoryLimit = (): number => this.maxMemory;
199
- public getHealthChecksEnabled = (): boolean => this.healthCheck;
200
- public getFailedHealthURL = () => this.failedHealthURL;
201
- public getQueueAlertURL = () => this.queueAlertURL;
202
- public getRejectAlertURL = () => this.rejectAlertURL;
203
- public getTimeoutAlertURL = () => this.timeoutAlertURL;
204
- public getErrorAlertURL = () => this.errorAlertURL;
205
-
206
- public hasDebugger = (): Promise<boolean> => exists(this.debuggerDir);
213
+ public getQueued(): number {
214
+ return this.queued;
215
+ }
216
+ public getTimeout(): number {
217
+ return this.timeout;
218
+ }
219
+ public getStatic(): string {
220
+ return this.static;
221
+ }
222
+ public getDebuggerDir(): string {
223
+ return this.debuggerDir;
224
+ }
225
+ public getRetries(): number {
226
+ return this.retries;
227
+ }
228
+ public getAllowFileProtocol(): boolean {
229
+ return this.allowFileProtocol;
230
+ }
231
+ public getCPULimit(): number {
232
+ return this.maxCpu;
233
+ }
234
+ public getMemoryLimit(): number {
235
+ return this.maxMemory;
236
+ }
237
+ public getHealthChecksEnabled(): boolean {
238
+ return this.healthCheck;
239
+ }
240
+ public getFailedHealthURL() {
241
+ return this.failedHealthURL;
242
+ }
243
+ public getQueueAlertURL() {
244
+ return this.queueAlertURL;
245
+ }
246
+ public getRejectAlertURL() {
247
+ return this.rejectAlertURL;
248
+ }
249
+ public getTimeoutAlertURL() {
250
+ return this.timeoutAlertURL;
251
+ }
252
+ public getErrorAlertURL() {
253
+ return this.errorAlertURL;
254
+ }
255
+
256
+ public hasDebugger(): Promise<boolean> {
257
+ return exists(this.debuggerDir);
258
+ }
207
259
 
208
260
  /**
209
261
  * If true, allows GET style calls on our browser-based APIs, using
210
262
  * ?body=JSON format.
211
263
  */
212
- public getAllowGetCalls = (): boolean => this.allowGet;
264
+ public getAllowGetCalls(): boolean {
265
+ return this.allowGet;
266
+ }
213
267
 
214
268
  /**
215
269
  * Determines if CORS is allowed
216
270
  */
217
- public getAllowCORS = (): boolean => this.allowCors;
271
+ public getAllowCORS(): boolean {
272
+ return this.allowCors;
273
+ }
218
274
 
219
- public getDataDir = async (): Promise<string> => {
275
+ public async getDataDir(): Promise<string> {
220
276
  if (this.createDataDir && !(await exists(this.dataDir))) {
221
277
  await mkdir(this.dataDir, { recursive: true }).catch((err) => {
222
278
  throw new Error(`Error in creating the data directory ${err}, exiting`);
@@ -231,9 +287,9 @@ export class Config extends EventEmitter {
231
287
  }
232
288
 
233
289
  return this.dataDir;
234
- };
290
+ }
235
291
 
236
- public getDownloadsDir = async (): Promise<string> => {
292
+ public async getDownloadsDir(): Promise<string> {
237
293
  if (this.createDownloadsDir && !(await exists(this.downloadsDir))) {
238
294
  await mkdir(this.downloadsDir, { recursive: true }).catch((err) => {
239
295
  throw new Error(
@@ -250,27 +306,27 @@ export class Config extends EventEmitter {
250
306
  }
251
307
 
252
308
  return this.downloadsDir;
253
- };
309
+ }
254
310
 
255
311
  /**
256
312
  * Repeats the TOKEN parameter up to 24 characters so we can
257
313
  * do AES encoding for saving things to disk and generating
258
314
  * secure links.
259
315
  */
260
- public getAESKey = () => {
316
+ public getAESKey() {
261
317
  const aesToken = this.token || 'browserless';
262
318
  return Buffer.from(aesToken.repeat(keyLength).substring(0, keyLength));
263
- };
319
+ }
264
320
 
265
- public getMetricsJSONPath = () => this.metricsJSONPath;
321
+ public getMetricsJSONPath() {
322
+ return this.metricsJSONPath;
323
+ }
266
324
 
267
- public setPwVersions = (versions: { [key: string]: string }) => {
268
- this.pwVersions = versions;
269
- };
325
+ public setPwVersions(versions: { [key: string]: string }) {
326
+ return (this.pwVersions = versions);
327
+ }
270
328
 
271
- public loadPwVersion = async (
272
- version: string,
273
- ): Promise<typeof playwright> => {
329
+ public async loadPwVersion(version: string): Promise<typeof playwright> {
274
330
  const versions = this.getPwVersions();
275
331
 
276
332
  try {
@@ -279,9 +335,9 @@ export class Config extends EventEmitter {
279
335
  debug.log('Error importing Playwright. Using default version', err);
280
336
  return playwright;
281
337
  }
282
- };
338
+ }
283
339
 
284
- public setDataDir = async (newDataDir: string): Promise<string> => {
340
+ public async setDataDir(newDataDir: string): Promise<string> {
285
341
  if (!(await exists(newDataDir))) {
286
342
  throw new Error(
287
343
  `New data-directory "${newDataDir}" doesn't exist, did you forget to mount or create it?`,
@@ -290,121 +346,121 @@ export class Config extends EventEmitter {
290
346
  this.dataDir = newDataDir;
291
347
  this.emit('data-dir', newDataDir);
292
348
  return this.dataDir;
293
- };
349
+ }
294
350
 
295
- public setRoutes = (newRoutePath: string): string => {
351
+ public setRoutes(newRoutePath: string): string {
296
352
  this.emit('routes', newRoutePath);
297
353
  return (this.routes = newRoutePath);
298
- };
354
+ }
299
355
 
300
- public setConcurrent = (newConcurrent: number): number => {
356
+ public setConcurrent(newConcurrent: number): number {
301
357
  this.emit('concurrent', newConcurrent);
302
358
  return (this.concurrent = newConcurrent);
303
- };
359
+ }
304
360
 
305
- public setQueued = (newQueued: number): number => {
361
+ public setQueued(newQueued: number): number {
306
362
  this.emit('queued', newQueued);
307
363
  return (this.queued = newQueued);
308
- };
364
+ }
309
365
 
310
- public setToken = (newToken: string | null): string | null => {
366
+ public setToken(newToken: string | null): string | null {
311
367
  this.emit('token', newToken);
312
368
  return (this.token = newToken);
313
- };
369
+ }
314
370
 
315
- public setTimeout = (newTimeout: number): number => {
371
+ public setTimeout(newTimeout: number): number {
316
372
  this.emit('timeout', newTimeout);
317
373
  return (this.timeout = newTimeout);
318
- };
374
+ }
319
375
 
320
- public setStatic = (newStatic: string): string => {
376
+ public setStatic(newStatic: string): string {
321
377
  this.emit('static', newStatic);
322
378
  return (this.static = newStatic);
323
- };
379
+ }
324
380
 
325
- public setRetries = (newRetries: number): number => {
381
+ public setRetries(newRetries: number): number {
326
382
  this.emit('retries', newRetries);
327
383
  return (this.retries = newRetries);
328
- };
384
+ }
329
385
 
330
- public setCPULimit = (limit: number): number => {
386
+ public setCPULimit(limit: number): number {
331
387
  this.emit('cpuLimit', limit);
332
388
  return (this.maxCpu = limit);
333
- };
389
+ }
334
390
 
335
- public setMemoryLimit = (limit: number): number => {
391
+ public setMemoryLimit(limit: number): number {
336
392
  this.emit('memoryLimit', limit);
337
393
  return (this.maxMemory = limit);
338
- };
394
+ }
339
395
 
340
- public enableHealthChecks = (enable: boolean): boolean => {
396
+ public enableHealthChecks(enable: boolean): boolean {
341
397
  this.emit('healthCheck', enable);
342
398
  return (this.healthCheck = enable);
343
- };
399
+ }
344
400
 
345
- public enableGETRequests = (enable: boolean): boolean => {
401
+ public enableGETRequests(enable: boolean): boolean {
346
402
  this.emit('getRequests', enable);
347
403
  return (this.allowGet = enable);
348
- };
404
+ }
349
405
 
350
- public enableCORS = (enable: boolean): boolean => {
406
+ public enableCORS(enable: boolean): boolean {
351
407
  this.emit('cors', enable);
352
408
  return (this.allowCors = enable);
353
- };
409
+ }
354
410
 
355
- public setCORSMethods = (methods: string): string => {
411
+ public setCORSMethods(methods: string): string {
356
412
  this.emit('corsMethods', methods);
357
413
  return (this.corsMethods = methods);
358
- };
414
+ }
359
415
 
360
- public setCORSOrigin = (origin: string): string => {
416
+ public setCORSOrigin(origin: string): string {
361
417
  this.emit('corsOrigin', origin);
362
418
  return (this.corsOrigin = origin);
363
- };
419
+ }
364
420
 
365
- public setCORSMaxAge = (maxAge: number): number => {
421
+ public setCORSMaxAge(maxAge: number): number {
366
422
  this.emit('corsMaxAge', maxAge);
367
423
  return (this.corsMaxAge = maxAge);
368
- };
369
- public setFailedHealthURL = (url: string | null): string | null => {
424
+ }
425
+ public setFailedHealthURL(url: string | null): string | null {
370
426
  this.emit('failedHealthURL');
371
427
  return (this.failedHealthURL = url);
372
- };
428
+ }
373
429
 
374
- public setQueueAlertURL = (url: string | null): string | null => {
430
+ public setQueueAlertURL(url: string | null): string | null {
375
431
  this.emit('queueAlertURL');
376
432
  return (this.queueAlertURL = url);
377
- };
433
+ }
378
434
 
379
- public setRejectAlertURL = (url: string | null): string | null => {
435
+ public setRejectAlertURL(url: string | null): string | null {
380
436
  this.emit('rejectAlertURL');
381
437
  return (this.rejectAlertURL = url);
382
- };
438
+ }
383
439
 
384
- public setTimeoutAlertURL = (url: string | null): string | null => {
440
+ public setTimeoutAlertURL(url: string | null): string | null {
385
441
  this.emit('timeoutAlertURL');
386
442
  return (this.timeoutAlertURL = url);
387
- };
443
+ }
388
444
 
389
- public setErrorAlertURL = (url: string | null): string | null => {
445
+ public setErrorAlertURL(url: string | null): string | null {
390
446
  this.emit('errorAlertURL');
391
447
  return (this.errorAlertURL = url);
392
- };
448
+ }
393
449
 
394
- public setMetricsJSONPath = (path: string) => {
450
+ public setMetricsJSONPath(path: string) {
395
451
  this.emit('metricsJSONPath', path);
396
452
  return (this.metricsJSONPath = path);
397
- };
453
+ }
398
454
 
399
- public setPort = (port: number) => {
455
+ public setPort(port: number) {
400
456
  this.emit('port', port);
401
457
  return (this.port = port);
402
- };
458
+ }
403
459
 
404
- public setAllowFileProtocol = (allow: boolean): boolean => {
460
+ public setAllowFileProtocol(allow: boolean): boolean {
405
461
  this.emit('allowFileProtocol', allow);
406
462
  return (this.allowFileProtocol = allow);
407
- };
463
+ }
408
464
 
409
465
  /**
410
466
  * Returns the fully-qualified server address, which
@@ -415,12 +471,13 @@ export class Config extends EventEmitter {
415
471
  *
416
472
  * @returns Fully-qualified server address
417
473
  */
418
- public getServerAddress = (): string =>
419
- this.port === 443
474
+ public getServerAddress(): string {
475
+ return this.port === 443
420
476
  ? `https://${this.host}:${this.port}`
421
477
  : this.port === 80
422
478
  ? `http://${this.host}`
423
479
  : `http://${this.host}:${this.port}`;
480
+ }
424
481
 
425
482
  /**
426
483
  * Returns the fully-qualified URL for the
@@ -430,8 +487,9 @@ export class Config extends EventEmitter {
430
487
  *
431
488
  * @returns {string} The URL to reach the server
432
489
  */
433
- public getExternalAddress = (): string =>
434
- this.external ?? this.getServerAddress();
490
+ public getExternalAddress(): string {
491
+ return this.external ?? this.getServerAddress();
492
+ }
435
493
 
436
494
  /**
437
495
  * Set the external URL, which Browserless uses for encoding
@@ -440,7 +498,9 @@ export class Config extends EventEmitter {
440
498
  * @param address The fully-qualified URL, eg https://www.example.com/
441
499
  * @returns {string} The address
442
500
  */
443
- public setExternalAddress = (address: string) => (this.external = address);
501
+ public setExternalAddress(address: string) {
502
+ return (this.external = address);
503
+ }
444
504
 
445
505
  /**
446
506
  * Returns the fully-qualified WebSocket URL for the
@@ -450,14 +510,14 @@ export class Config extends EventEmitter {
450
510
  *
451
511
  * @returns {string} The URL to reach the server
452
512
  */
453
- public getExternalWebSocketAddress = (): string => {
513
+ public getExternalWebSocketAddress(): string {
454
514
  const httpAddress = new URL(this.external ?? this.getServerAddress());
455
515
  httpAddress.protocol = httpAddress.protocol.startsWith('https')
456
516
  ? 'wss:'
457
517
  : 'ws:';
458
518
 
459
519
  return httpAddress.href;
460
- };
520
+ }
461
521
 
462
522
  /**
463
523
  * When CORS is enabled, returns relevant CORS headers
@@ -465,26 +525,28 @@ export class Config extends EventEmitter {
465
525
  * overridden by specifying `CORS_ALLOW_METHODS`, `CORS_ALLOW_ORIGIN`,
466
526
  * and `CORS_MAX_AGE`
467
527
  */
468
- public getCORSHeaders = (): {
528
+ public getCORSHeaders(): {
469
529
  'Access-Control-Allow-Methods': string;
470
530
  'Access-Control-Allow-Origin': string;
471
531
  'Access-Control-Max-Age': number;
472
- } => ({
473
- 'Access-Control-Allow-Methods': this.corsMethods,
474
- 'Access-Control-Allow-Origin': this.corsOrigin,
475
- 'Access-Control-Max-Age': this.corsMaxAge,
476
- });
532
+ } {
533
+ return {
534
+ 'Access-Control-Allow-Methods': this.corsMethods,
535
+ 'Access-Control-Allow-Origin': this.corsOrigin,
536
+ 'Access-Control-Max-Age': this.corsMaxAge,
537
+ };
538
+ }
477
539
 
478
540
  /**
479
541
  * Implement any browserless-core-specific shutdown logic here.
480
542
  * Calls the empty-SDK stop method for downstream implementations.
481
543
  */
482
- public shutdown = async () => {
544
+ public async shutdown() {
483
545
  await this.stop();
484
- };
546
+ }
485
547
 
486
548
  /**
487
549
  * Left blank for downstream SDK modules to optionally implement.
488
550
  */
489
- public stop = () => {};
551
+ public stop() {}
490
552
  }
@@ -21,11 +21,11 @@ export class FileSystem extends EventEmitter {
21
21
  * @param newContent A string of new content to add to the file
22
22
  * @returns void
23
23
  */
24
- append = async (
24
+ public async append(
25
25
  path: string,
26
26
  newContent: string,
27
27
  shouldEncode: boolean,
28
- ): Promise<void> => {
28
+ ): Promise<void> {
29
29
  const contents = await this.read(path, shouldEncode);
30
30
 
31
31
  contents.push(newContent);
@@ -36,7 +36,7 @@ export class FileSystem extends EventEmitter {
36
36
  : contents.join('\n');
37
37
 
38
38
  return writeFile(path, encoded.toString());
39
- };
39
+ }
40
40
 
41
41
  /**
42
42
  * Reads contents from the local map, if any exist, or loads
@@ -45,7 +45,7 @@ export class FileSystem extends EventEmitter {
45
45
  * @param path The filepath of the contents to read
46
46
  * @returns Promise of the contents separated by newlines
47
47
  */
48
- read = async (path: string, encoded: boolean): Promise<string[]> => {
48
+ public async read(path: string, encoded: boolean): Promise<string[]> {
49
49
  const hasKey = this.fsMap.has(path);
50
50
 
51
51
  if (hasKey) {
@@ -61,18 +61,18 @@ export class FileSystem extends EventEmitter {
61
61
  this.fsMap.set(path, splitContents);
62
62
 
63
63
  return splitContents;
64
- };
64
+ }
65
65
 
66
66
  /**
67
67
  * Implement any browserless-core-specific shutdown logic here.
68
68
  * Calls the empty-SDK stop method for downstream implementations.
69
69
  */
70
- public shutdown = async () => {
71
- await this.stop();
72
- };
70
+ public async shutdown() {
71
+ return await this.stop();
72
+ }
73
73
 
74
74
  /**
75
75
  * Left blank for downstream SDK modules to optionally implement.
76
76
  */
77
- public stop = () => {};
77
+ public stop() {}
78
78
  }
package/src/hooks.ts CHANGED
@@ -39,12 +39,12 @@ export class Hooks extends EventEmitter {
39
39
  * Implement any browserless-core-specific shutdown logic here.
40
40
  * Calls the empty-SDK stop method for downstream implementations.
41
41
  */
42
- public shutdown = async () => {
43
- await this.stop();
44
- };
42
+ public async shutdown() {
43
+ return await this.stop();
44
+ }
45
45
 
46
46
  /**
47
47
  * Left blank for downstream SDK modules to optionally implement.
48
48
  */
49
- public stop = () => {};
49
+ public stop() {}
50
50
  }
package/src/limiter.ts CHANGED
@@ -19,7 +19,7 @@ export type ErrorFn<TArgs extends unknown[]> = (...args: TArgs) => void;
19
19
  interface Job {
20
20
  (): Promise<unknown>;
21
21
  args: unknown[];
22
- onTimeoutFn: (job: Job) => unknown;
22
+ onTimeoutFn(job: Job): unknown;
23
23
  start: number;
24
24
  timeout: number;
25
25
  }
@@ -62,15 +62,15 @@ export class Limiter extends q {
62
62
  });
63
63
 
64
64
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
- this.addEventListener('timeout', this.handleJobTimeout as any);
65
+ this.addEventListener('timeout', this.handleJobTimeout.bind(this) as any);
66
66
 
67
67
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
- this.addEventListener('success', this.handleSuccess as any);
68
+ this.addEventListener('success', this.handleSuccess.bind(this) as any);
69
69
 
70
70
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
71
- this.addEventListener('error', this.handleFail as any);
71
+ this.addEventListener('error', this.handleFail.bind(this) as any);
72
72
 
73
- this.addEventListener('end', this.handleEnd);
73
+ this.addEventListener('end', this.handleEnd.bind(this));
74
74
  }
75
75
 
76
76
  protected handleEnd() {
@@ -160,12 +160,12 @@ export class Limiter extends q {
160
160
  return this.length < this.concurrency + this.queued;
161
161
  }
162
162
 
163
- public limit = <TArgs extends unknown[], TResult>(
163
+ public limit<TArgs extends unknown[], TResult>(
164
164
  limitFn: LimitFn<TArgs, TResult>,
165
165
  overCapacityFn: ErrorFn<TArgs>,
166
166
  onTimeoutFn: ErrorFn<TArgs>,
167
167
  timeoutOverrideFn: (...args: TArgs) => number | undefined,
168
- ): LimitFn<TArgs, unknown> => {
168
+ ): LimitFn<TArgs, unknown> {
169
169
  return (...args: TArgs) =>
170
170
  new Promise(async (res, rej) => {
171
171
  const timeout = timeoutOverrideFn(...args) ?? this.timeout;
@@ -227,18 +227,18 @@ export class Limiter extends q {
227
227
 
228
228
  return bound;
229
229
  });
230
- };
230
+ }
231
231
 
232
232
  /**
233
233
  * Implement any browserless-core-specific shutdown logic here.
234
234
  * Calls the empty-SDK stop method for downstream implementations.
235
235
  */
236
- public shutdown = async () => {
237
- await this.stop();
238
- };
236
+ public async shutdown() {
237
+ return await this.stop();
238
+ }
239
239
 
240
240
  /**
241
241
  * Left blank for downstream SDK modules to optionally implement.
242
242
  */
243
- public stop = () => {};
243
+ public stop() {}
244
244
  }
package/src/logger.ts CHANGED
@@ -26,27 +26,27 @@ export class Logger {
26
26
  return this.request ? this.request.socket.remoteAddress ?? 'Unknown' : '';
27
27
  }
28
28
 
29
- public trace = (...messages: unknown[]) => {
29
+ public trace(...messages: unknown[]) {
30
30
  this._trace(this.reqInfo, ...messages);
31
- };
31
+ }
32
32
 
33
- public debug = (...messages: unknown[]) => {
33
+ public debug(...messages: unknown[]) {
34
34
  this._debug(this.reqInfo, ...messages);
35
- };
35
+ }
36
36
 
37
- public info = (...messages: unknown[]) => {
37
+ public info(...messages: unknown[]) {
38
38
  this._info(this.reqInfo, ...messages);
39
- };
39
+ }
40
40
 
41
- public warn = (...messages: unknown[]) => {
41
+ public warn(...messages: unknown[]) {
42
42
  this._warn(this.reqInfo, ...messages);
43
- };
43
+ }
44
44
 
45
- public error = (...messages: unknown[]) => {
45
+ public error(...messages: unknown[]) {
46
46
  this._error(this.reqInfo, ...messages);
47
- };
47
+ }
48
48
 
49
- public fatal = (...messages: unknown[]) => {
49
+ public fatal(...messages: unknown[]) {
50
50
  this._fatal(this.reqInfo, ...messages);
51
- };
51
+ }
52
52
  }