@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/build/config.js CHANGED
@@ -142,49 +142,99 @@ export class Config extends EventEmitter {
142
142
  timeoutAlertURL = process.env.TIMEOUT_ALERT_URL ?? null;
143
143
  errorAlertURL = process.env.ERROR_ALERT_URL ?? null;
144
144
  pwVersions = {};
145
- getRoutes = () => this.routes;
146
- getHost = () => this.host;
147
- getPort = () => this.port;
148
- getIsWin = () => this.isWin;
149
- getToken = () => this.token;
150
- getDebug = () => this.debug;
151
- getPwVersions = () => this.pwVersions;
145
+ getRoutes() {
146
+ return this.routes;
147
+ }
148
+ getHost() {
149
+ return this.host;
150
+ }
151
+ getPort() {
152
+ return this.port;
153
+ }
154
+ getIsWin() {
155
+ return this.isWin;
156
+ }
157
+ getToken() {
158
+ return this.token;
159
+ }
160
+ getDebug() {
161
+ return this.debug;
162
+ }
163
+ getPwVersions() {
164
+ return this.pwVersions;
165
+ }
152
166
  /**
153
167
  * The maximum number of concurrent sessions allowed. Set
154
168
  * to "-1" or "Infinity" for no limit.
155
169
  * @returns number
156
170
  */
157
- getConcurrent = () => this.concurrent;
171
+ getConcurrent() {
172
+ return this.concurrent;
173
+ }
158
174
  /**
159
175
  * The maximum number of queued sessions allowed. Set to
160
176
  * "-1" or "Infinity" for no limit.
161
177
  * @returns number
162
178
  */
163
- getQueued = () => this.queued;
164
- getTimeout = () => this.timeout;
165
- getStatic = () => this.static;
166
- getDebuggerDir = () => this.debuggerDir;
167
- getRetries = () => this.retries;
168
- getAllowFileProtocol = () => this.allowFileProtocol;
169
- getCPULimit = () => this.maxCpu;
170
- getMemoryLimit = () => this.maxMemory;
171
- getHealthChecksEnabled = () => this.healthCheck;
172
- getFailedHealthURL = () => this.failedHealthURL;
173
- getQueueAlertURL = () => this.queueAlertURL;
174
- getRejectAlertURL = () => this.rejectAlertURL;
175
- getTimeoutAlertURL = () => this.timeoutAlertURL;
176
- getErrorAlertURL = () => this.errorAlertURL;
177
- hasDebugger = () => exists(this.debuggerDir);
179
+ getQueued() {
180
+ return this.queued;
181
+ }
182
+ getTimeout() {
183
+ return this.timeout;
184
+ }
185
+ getStatic() {
186
+ return this.static;
187
+ }
188
+ getDebuggerDir() {
189
+ return this.debuggerDir;
190
+ }
191
+ getRetries() {
192
+ return this.retries;
193
+ }
194
+ getAllowFileProtocol() {
195
+ return this.allowFileProtocol;
196
+ }
197
+ getCPULimit() {
198
+ return this.maxCpu;
199
+ }
200
+ getMemoryLimit() {
201
+ return this.maxMemory;
202
+ }
203
+ getHealthChecksEnabled() {
204
+ return this.healthCheck;
205
+ }
206
+ getFailedHealthURL() {
207
+ return this.failedHealthURL;
208
+ }
209
+ getQueueAlertURL() {
210
+ return this.queueAlertURL;
211
+ }
212
+ getRejectAlertURL() {
213
+ return this.rejectAlertURL;
214
+ }
215
+ getTimeoutAlertURL() {
216
+ return this.timeoutAlertURL;
217
+ }
218
+ getErrorAlertURL() {
219
+ return this.errorAlertURL;
220
+ }
221
+ hasDebugger() {
222
+ return exists(this.debuggerDir);
223
+ }
178
224
  /**
179
225
  * If true, allows GET style calls on our browser-based APIs, using
180
226
  * ?body=JSON format.
181
227
  */
182
- getAllowGetCalls = () => this.allowGet;
228
+ getAllowGetCalls() {
229
+ return this.allowGet;
230
+ }
183
231
  /**
184
232
  * Determines if CORS is allowed
185
233
  */
186
- getAllowCORS = () => this.allowCors;
187
- getDataDir = async () => {
234
+ getAllowCORS() {
235
+ return this.allowCors;
236
+ }
237
+ async getDataDir() {
188
238
  if (this.createDataDir && !(await exists(this.dataDir))) {
189
239
  await mkdir(this.dataDir, { recursive: true }).catch((err) => {
190
240
  throw new Error(`Error in creating the data directory ${err}, exiting`);
@@ -195,8 +245,8 @@ export class Config extends EventEmitter {
195
245
  throw new Error(`"${this.dataDir}" Directory doesn't exist, did you forget to mount or make it?`);
196
246
  }
197
247
  return this.dataDir;
198
- };
199
- getDownloadsDir = async () => {
248
+ }
249
+ async getDownloadsDir() {
200
250
  if (this.createDownloadsDir && !(await exists(this.downloadsDir))) {
201
251
  await mkdir(this.downloadsDir, { recursive: true }).catch((err) => {
202
252
  throw new Error(`Error in creating the downloads directory ${err}, exiting`);
@@ -207,21 +257,23 @@ export class Config extends EventEmitter {
207
257
  throw new Error(`"${this.downloadsDir}" Directory doesn't exist, did you forget to mount or make it?`);
208
258
  }
209
259
  return this.downloadsDir;
210
- };
260
+ }
211
261
  /**
212
262
  * Repeats the TOKEN parameter up to 24 characters so we can
213
263
  * do AES encoding for saving things to disk and generating
214
264
  * secure links.
215
265
  */
216
- getAESKey = () => {
266
+ getAESKey() {
217
267
  const aesToken = this.token || 'browserless';
218
268
  return Buffer.from(aesToken.repeat(keyLength).substring(0, keyLength));
219
- };
220
- getMetricsJSONPath = () => this.metricsJSONPath;
221
- setPwVersions = (versions) => {
222
- this.pwVersions = versions;
223
- };
224
- loadPwVersion = async (version) => {
269
+ }
270
+ getMetricsJSONPath() {
271
+ return this.metricsJSONPath;
272
+ }
273
+ setPwVersions(versions) {
274
+ return (this.pwVersions = versions);
275
+ }
276
+ async loadPwVersion(version) {
225
277
  const versions = this.getPwVersions();
226
278
  try {
227
279
  return await import(versions[version] || versions['default']);
@@ -230,107 +282,107 @@ export class Config extends EventEmitter {
230
282
  debug.log('Error importing Playwright. Using default version', err);
231
283
  return playwright;
232
284
  }
233
- };
234
- setDataDir = async (newDataDir) => {
285
+ }
286
+ async setDataDir(newDataDir) {
235
287
  if (!(await exists(newDataDir))) {
236
288
  throw new Error(`New data-directory "${newDataDir}" doesn't exist, did you forget to mount or create it?`);
237
289
  }
238
290
  this.dataDir = newDataDir;
239
291
  this.emit('data-dir', newDataDir);
240
292
  return this.dataDir;
241
- };
242
- setRoutes = (newRoutePath) => {
293
+ }
294
+ setRoutes(newRoutePath) {
243
295
  this.emit('routes', newRoutePath);
244
296
  return (this.routes = newRoutePath);
245
- };
246
- setConcurrent = (newConcurrent) => {
297
+ }
298
+ setConcurrent(newConcurrent) {
247
299
  this.emit('concurrent', newConcurrent);
248
300
  return (this.concurrent = newConcurrent);
249
- };
250
- setQueued = (newQueued) => {
301
+ }
302
+ setQueued(newQueued) {
251
303
  this.emit('queued', newQueued);
252
304
  return (this.queued = newQueued);
253
- };
254
- setToken = (newToken) => {
305
+ }
306
+ setToken(newToken) {
255
307
  this.emit('token', newToken);
256
308
  return (this.token = newToken);
257
- };
258
- setTimeout = (newTimeout) => {
309
+ }
310
+ setTimeout(newTimeout) {
259
311
  this.emit('timeout', newTimeout);
260
312
  return (this.timeout = newTimeout);
261
- };
262
- setStatic = (newStatic) => {
313
+ }
314
+ setStatic(newStatic) {
263
315
  this.emit('static', newStatic);
264
316
  return (this.static = newStatic);
265
- };
266
- setRetries = (newRetries) => {
317
+ }
318
+ setRetries(newRetries) {
267
319
  this.emit('retries', newRetries);
268
320
  return (this.retries = newRetries);
269
- };
270
- setCPULimit = (limit) => {
321
+ }
322
+ setCPULimit(limit) {
271
323
  this.emit('cpuLimit', limit);
272
324
  return (this.maxCpu = limit);
273
- };
274
- setMemoryLimit = (limit) => {
325
+ }
326
+ setMemoryLimit(limit) {
275
327
  this.emit('memoryLimit', limit);
276
328
  return (this.maxMemory = limit);
277
- };
278
- enableHealthChecks = (enable) => {
329
+ }
330
+ enableHealthChecks(enable) {
279
331
  this.emit('healthCheck', enable);
280
332
  return (this.healthCheck = enable);
281
- };
282
- enableGETRequests = (enable) => {
333
+ }
334
+ enableGETRequests(enable) {
283
335
  this.emit('getRequests', enable);
284
336
  return (this.allowGet = enable);
285
- };
286
- enableCORS = (enable) => {
337
+ }
338
+ enableCORS(enable) {
287
339
  this.emit('cors', enable);
288
340
  return (this.allowCors = enable);
289
- };
290
- setCORSMethods = (methods) => {
341
+ }
342
+ setCORSMethods(methods) {
291
343
  this.emit('corsMethods', methods);
292
344
  return (this.corsMethods = methods);
293
- };
294
- setCORSOrigin = (origin) => {
345
+ }
346
+ setCORSOrigin(origin) {
295
347
  this.emit('corsOrigin', origin);
296
348
  return (this.corsOrigin = origin);
297
- };
298
- setCORSMaxAge = (maxAge) => {
349
+ }
350
+ setCORSMaxAge(maxAge) {
299
351
  this.emit('corsMaxAge', maxAge);
300
352
  return (this.corsMaxAge = maxAge);
301
- };
302
- setFailedHealthURL = (url) => {
353
+ }
354
+ setFailedHealthURL(url) {
303
355
  this.emit('failedHealthURL');
304
356
  return (this.failedHealthURL = url);
305
- };
306
- setQueueAlertURL = (url) => {
357
+ }
358
+ setQueueAlertURL(url) {
307
359
  this.emit('queueAlertURL');
308
360
  return (this.queueAlertURL = url);
309
- };
310
- setRejectAlertURL = (url) => {
361
+ }
362
+ setRejectAlertURL(url) {
311
363
  this.emit('rejectAlertURL');
312
364
  return (this.rejectAlertURL = url);
313
- };
314
- setTimeoutAlertURL = (url) => {
365
+ }
366
+ setTimeoutAlertURL(url) {
315
367
  this.emit('timeoutAlertURL');
316
368
  return (this.timeoutAlertURL = url);
317
- };
318
- setErrorAlertURL = (url) => {
369
+ }
370
+ setErrorAlertURL(url) {
319
371
  this.emit('errorAlertURL');
320
372
  return (this.errorAlertURL = url);
321
- };
322
- setMetricsJSONPath = (path) => {
373
+ }
374
+ setMetricsJSONPath(path) {
323
375
  this.emit('metricsJSONPath', path);
324
376
  return (this.metricsJSONPath = path);
325
- };
326
- setPort = (port) => {
377
+ }
378
+ setPort(port) {
327
379
  this.emit('port', port);
328
380
  return (this.port = port);
329
- };
330
- setAllowFileProtocol = (allow) => {
381
+ }
382
+ setAllowFileProtocol(allow) {
331
383
  this.emit('allowFileProtocol', allow);
332
384
  return (this.allowFileProtocol = allow);
333
- };
385
+ }
334
386
  /**
335
387
  * Returns the fully-qualified server address, which
336
388
  * includes host, protocol, and port for which the
@@ -340,11 +392,13 @@ export class Config extends EventEmitter {
340
392
  *
341
393
  * @returns Fully-qualified server address
342
394
  */
343
- getServerAddress = () => this.port === 443
344
- ? `https://${this.host}:${this.port}`
345
- : this.port === 80
346
- ? `http://${this.host}`
347
- : `http://${this.host}:${this.port}`;
395
+ getServerAddress() {
396
+ return this.port === 443
397
+ ? `https://${this.host}:${this.port}`
398
+ : this.port === 80
399
+ ? `http://${this.host}`
400
+ : `http://${this.host}:${this.port}`;
401
+ }
348
402
  /**
349
403
  * Returns the fully-qualified URL for the
350
404
  * external address that browserless might be
@@ -353,7 +407,9 @@ export class Config extends EventEmitter {
353
407
  *
354
408
  * @returns {string} The URL to reach the server
355
409
  */
356
- getExternalAddress = () => this.external ?? this.getServerAddress();
410
+ getExternalAddress() {
411
+ return this.external ?? this.getServerAddress();
412
+ }
357
413
  /**
358
414
  * Set the external URL, which Browserless uses for encoding
359
415
  * URLs over the HOST:PORT that it's bound to.
@@ -361,7 +417,9 @@ export class Config extends EventEmitter {
361
417
  * @param address The fully-qualified URL, eg https://www.example.com/
362
418
  * @returns {string} The address
363
419
  */
364
- setExternalAddress = (address) => (this.external = address);
420
+ setExternalAddress(address) {
421
+ return (this.external = address);
422
+ }
365
423
  /**
366
424
  * Returns the fully-qualified WebSocket URL for the
367
425
  * external address that browserless might be
@@ -370,33 +428,35 @@ export class Config extends EventEmitter {
370
428
  *
371
429
  * @returns {string} The URL to reach the server
372
430
  */
373
- getExternalWebSocketAddress = () => {
431
+ getExternalWebSocketAddress() {
374
432
  const httpAddress = new URL(this.external ?? this.getServerAddress());
375
433
  httpAddress.protocol = httpAddress.protocol.startsWith('https')
376
434
  ? 'wss:'
377
435
  : 'ws:';
378
436
  return httpAddress.href;
379
- };
437
+ }
380
438
  /**
381
439
  * When CORS is enabled, returns relevant CORS headers
382
440
  * to requests and for the OPTIONS call. Values can be
383
441
  * overridden by specifying `CORS_ALLOW_METHODS`, `CORS_ALLOW_ORIGIN`,
384
442
  * and `CORS_MAX_AGE`
385
443
  */
386
- getCORSHeaders = () => ({
387
- 'Access-Control-Allow-Methods': this.corsMethods,
388
- 'Access-Control-Allow-Origin': this.corsOrigin,
389
- 'Access-Control-Max-Age': this.corsMaxAge,
390
- });
444
+ getCORSHeaders() {
445
+ return {
446
+ 'Access-Control-Allow-Methods': this.corsMethods,
447
+ 'Access-Control-Allow-Origin': this.corsOrigin,
448
+ 'Access-Control-Max-Age': this.corsMaxAge,
449
+ };
450
+ }
391
451
  /**
392
452
  * Implement any browserless-core-specific shutdown logic here.
393
453
  * Calls the empty-SDK stop method for downstream implementations.
394
454
  */
395
- shutdown = async () => {
455
+ async shutdown() {
396
456
  await this.stop();
397
- };
457
+ }
398
458
  /**
399
459
  * Left blank for downstream SDK modules to optionally implement.
400
460
  */
401
- stop = () => { };
461
+ stop() { }
402
462
  }
@@ -17,7 +17,7 @@ export declare class FileSystem extends EventEmitter {
17
17
  * @param newContent A string of new content to add to the file
18
18
  * @returns void
19
19
  */
20
- append: (path: string, newContent: string, shouldEncode: boolean) => Promise<void>;
20
+ append(path: string, newContent: string, shouldEncode: boolean): Promise<void>;
21
21
  /**
22
22
  * Reads contents from the local map, if any exist, or loads
23
23
  * from the file system and hydrates the cache for the particular filepath
@@ -25,14 +25,14 @@ export declare class FileSystem extends EventEmitter {
25
25
  * @param path The filepath of the contents to read
26
26
  * @returns Promise of the contents separated by newlines
27
27
  */
28
- read: (path: string, encoded: boolean) => Promise<string[]>;
28
+ read(path: string, encoded: boolean): Promise<string[]>;
29
29
  /**
30
30
  * Implement any browserless-core-specific shutdown logic here.
31
31
  * Calls the empty-SDK stop method for downstream implementations.
32
32
  */
33
- shutdown: () => Promise<void>;
33
+ shutdown(): Promise<void>;
34
34
  /**
35
35
  * Left blank for downstream SDK modules to optionally implement.
36
36
  */
37
- stop: () => void;
37
+ stop(): void;
38
38
  }
@@ -20,7 +20,7 @@ export class FileSystem extends EventEmitter {
20
20
  * @param newContent A string of new content to add to the file
21
21
  * @returns void
22
22
  */
23
- append = async (path, newContent, shouldEncode) => {
23
+ async append(path, newContent, shouldEncode) {
24
24
  const contents = await this.read(path, shouldEncode);
25
25
  contents.push(newContent);
26
26
  this.fsMap.set(path, contents);
@@ -28,7 +28,7 @@ export class FileSystem extends EventEmitter {
28
28
  ? await encrypt(contents.join('\n'), this.currentAESKey)
29
29
  : contents.join('\n');
30
30
  return writeFile(path, encoded.toString());
31
- };
31
+ }
32
32
  /**
33
33
  * Reads contents from the local map, if any exist, or loads
34
34
  * from the file system and hydrates the cache for the particular filepath
@@ -36,7 +36,7 @@ export class FileSystem extends EventEmitter {
36
36
  * @param path The filepath of the contents to read
37
37
  * @returns Promise of the contents separated by newlines
38
38
  */
39
- read = async (path, encoded) => {
39
+ async read(path, encoded) {
40
40
  const hasKey = this.fsMap.has(path);
41
41
  if (hasKey) {
42
42
  return this.fsMap.get(path);
@@ -48,16 +48,16 @@ export class FileSystem extends EventEmitter {
48
48
  const splitContents = decoded.length ? decoded.split('\n') : [];
49
49
  this.fsMap.set(path, splitContents);
50
50
  return splitContents;
51
- };
51
+ }
52
52
  /**
53
53
  * Implement any browserless-core-specific shutdown logic here.
54
54
  * Calls the empty-SDK stop method for downstream implementations.
55
55
  */
56
- shutdown = async () => {
57
- await this.stop();
58
- };
56
+ async shutdown() {
57
+ return await this.stop();
58
+ }
59
59
  /**
60
60
  * Left blank for downstream SDK modules to optionally implement.
61
61
  */
62
- stop = () => { };
62
+ stop() { }
63
63
  }
package/build/hooks.d.ts CHANGED
@@ -10,9 +10,9 @@ export declare class Hooks extends EventEmitter {
10
10
  * Implement any browserless-core-specific shutdown logic here.
11
11
  * Calls the empty-SDK stop method for downstream implementations.
12
12
  */
13
- shutdown: () => Promise<void>;
13
+ shutdown(): Promise<void>;
14
14
  /**
15
15
  * Left blank for downstream SDK modules to optionally implement.
16
16
  */
17
- stop: () => void;
17
+ stop(): void;
18
18
  }
package/build/hooks.js CHANGED
@@ -27,11 +27,11 @@ export class Hooks extends EventEmitter {
27
27
  * Implement any browserless-core-specific shutdown logic here.
28
28
  * Calls the empty-SDK stop method for downstream implementations.
29
29
  */
30
- shutdown = async () => {
31
- await this.stop();
32
- };
30
+ async shutdown() {
31
+ return await this.stop();
32
+ }
33
33
  /**
34
34
  * Left blank for downstream SDK modules to optionally implement.
35
35
  */
36
- stop = () => { };
36
+ stop() { }
37
37
  }
@@ -5,7 +5,7 @@ export type ErrorFn<TArgs extends unknown[]> = (...args: TArgs) => void;
5
5
  interface Job {
6
6
  (): Promise<unknown>;
7
7
  args: unknown[];
8
- onTimeoutFn: (job: Job) => unknown;
8
+ onTimeoutFn(job: Job): unknown;
9
9
  start: number;
10
10
  timeout: number;
11
11
  }
@@ -43,15 +43,15 @@ export declare class Limiter extends q {
43
43
  get willQueue(): boolean;
44
44
  get concurrencySize(): number;
45
45
  get hasCapacity(): boolean;
46
- limit: <TArgs extends unknown[], TResult>(limitFn: LimitFn<TArgs, TResult>, overCapacityFn: ErrorFn<TArgs>, onTimeoutFn: ErrorFn<TArgs>, timeoutOverrideFn: (...args: TArgs) => number | undefined) => LimitFn<TArgs, unknown>;
46
+ limit<TArgs extends unknown[], TResult>(limitFn: LimitFn<TArgs, TResult>, overCapacityFn: ErrorFn<TArgs>, onTimeoutFn: ErrorFn<TArgs>, timeoutOverrideFn: (...args: TArgs) => number | undefined): LimitFn<TArgs, unknown>;
47
47
  /**
48
48
  * Implement any browserless-core-specific shutdown logic here.
49
49
  * Calls the empty-SDK stop method for downstream implementations.
50
50
  */
51
- shutdown: () => Promise<void>;
51
+ shutdown(): Promise<void>;
52
52
  /**
53
53
  * Left blank for downstream SDK modules to optionally implement.
54
54
  */
55
- stop: () => void;
55
+ stop(): void;
56
56
  }
57
57
  export {};
package/build/limiter.js CHANGED
@@ -34,12 +34,12 @@ export class Limiter extends q {
34
34
  this.timeout = timeout <= 0 ? 0 : timeout;
35
35
  });
36
36
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
- this.addEventListener('timeout', this.handleJobTimeout);
37
+ this.addEventListener('timeout', this.handleJobTimeout.bind(this));
38
38
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
- this.addEventListener('success', this.handleSuccess);
39
+ this.addEventListener('success', this.handleSuccess.bind(this));
40
40
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
- this.addEventListener('error', this.handleFail);
42
- this.addEventListener('end', this.handleEnd);
41
+ this.addEventListener('error', this.handleFail.bind(this));
42
+ this.addEventListener('end', this.handleEnd.bind(this));
43
43
  }
44
44
  handleEnd() {
45
45
  this.logQueue('All jobs complete.');
@@ -100,7 +100,7 @@ export class Limiter extends q {
100
100
  get hasCapacity() {
101
101
  return this.length < this.concurrency + this.queued;
102
102
  }
103
- limit = (limitFn, overCapacityFn, onTimeoutFn, timeoutOverrideFn) => {
103
+ limit(limitFn, overCapacityFn, onTimeoutFn, timeoutOverrideFn) {
104
104
  return (...args) => new Promise(async (res, rej) => {
105
105
  const timeout = timeoutOverrideFn(...args) ?? this.timeout;
106
106
  this.logQueue(`Adding to queue, max time allowed is ${timeout.toLocaleString()}ms`);
@@ -148,16 +148,16 @@ export class Limiter extends q {
148
148
  this.push(job);
149
149
  return bound;
150
150
  });
151
- };
151
+ }
152
152
  /**
153
153
  * Implement any browserless-core-specific shutdown logic here.
154
154
  * Calls the empty-SDK stop method for downstream implementations.
155
155
  */
156
- shutdown = async () => {
157
- await this.stop();
158
- };
156
+ async shutdown() {
157
+ return await this.stop();
158
+ }
159
159
  /**
160
160
  * Left blank for downstream SDK modules to optionally implement.
161
161
  */
162
- stop = () => { };
162
+ stop() { }
163
163
  }
package/build/logger.d.ts CHANGED
@@ -10,10 +10,10 @@ export declare class Logger {
10
10
  protected _fatal: (...args: unknown[]) => void;
11
11
  constructor(prefix: string, request?: Request | undefined);
12
12
  protected get reqInfo(): string;
13
- trace: (...messages: unknown[]) => void;
14
- debug: (...messages: unknown[]) => void;
15
- info: (...messages: unknown[]) => void;
16
- warn: (...messages: unknown[]) => void;
17
- error: (...messages: unknown[]) => void;
18
- fatal: (...messages: unknown[]) => void;
13
+ trace(...messages: unknown[]): void;
14
+ debug(...messages: unknown[]): void;
15
+ info(...messages: unknown[]): void;
16
+ warn(...messages: unknown[]): void;
17
+ error(...messages: unknown[]): void;
18
+ fatal(...messages: unknown[]): void;
19
19
  }
package/build/logger.js CHANGED
@@ -22,22 +22,22 @@ export class Logger {
22
22
  get reqInfo() {
23
23
  return this.request ? this.request.socket.remoteAddress ?? 'Unknown' : '';
24
24
  }
25
- trace = (...messages) => {
25
+ trace(...messages) {
26
26
  this._trace(this.reqInfo, ...messages);
27
- };
28
- debug = (...messages) => {
27
+ }
28
+ debug(...messages) {
29
29
  this._debug(this.reqInfo, ...messages);
30
- };
31
- info = (...messages) => {
30
+ }
31
+ info(...messages) {
32
32
  this._info(this.reqInfo, ...messages);
33
- };
34
- warn = (...messages) => {
33
+ }
34
+ warn(...messages) {
35
35
  this._warn(this.reqInfo, ...messages);
36
- };
37
- error = (...messages) => {
36
+ }
37
+ error(...messages) {
38
38
  this._error(this.reqInfo, ...messages);
39
- };
40
- fatal = (...messages) => {
39
+ }
40
+ fatal(...messages) {
41
41
  this._fatal(this.reqInfo, ...messages);
42
- };
42
+ }
43
43
  }