@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.
- package/CHANGELOG.md +9 -1
- package/bin/scaffold/README.md +6 -5
- package/bin/scaffold/src/hello-world.http.ts +3 -3
- package/build/browserless.d.ts +3 -3
- package/build/browserless.js +6 -6
- package/build/browsers/chromium.cdp.d.ts +12 -12
- package/build/browsers/chromium.cdp.js +77 -65
- package/build/browsers/chromium.playwright.d.ts +11 -11
- package/build/browsers/chromium.playwright.js +42 -34
- package/build/browsers/firefox.playwright.d.ts +11 -11
- package/build/browsers/firefox.playwright.js +42 -34
- package/build/browsers/index.d.ts +14 -14
- package/build/browsers/index.js +27 -25
- package/build/browsers/webkit.playwright.d.ts +11 -11
- package/build/browsers/webkit.playwright.js +43 -35
- package/build/config.d.ts +65 -63
- package/build/config.js +162 -102
- package/build/file-system.d.ts +4 -4
- package/build/file-system.js +8 -8
- package/build/hooks.d.ts +2 -2
- package/build/hooks.js +4 -4
- package/build/limiter.d.ts +4 -4
- package/build/limiter.js +10 -10
- package/build/logger.d.ts +6 -6
- package/build/logger.js +12 -12
- package/build/metrics.d.ts +12 -12
- package/build/metrics.js +23 -23
- package/build/monitoring.d.ts +4 -4
- package/build/monitoring.js +8 -8
- package/build/router.d.ts +8 -8
- package/build/router.js +74 -70
- package/build/routes/chrome/http/pdf.post.body.json +8 -8
- package/build/routes/chrome/http/scrape.post.body.json +8 -8
- package/build/routes/chrome/http/screenshot.post.body.json +8 -8
- package/build/routes/chromium/http/content.post.body.json +8 -8
- package/build/routes/chromium/http/pdf.post.body.json +8 -8
- package/build/routes/chromium/http/scrape.post.body.json +8 -8
- package/build/routes/chromium/http/screenshot.post.body.json +8 -8
- package/build/routes/firefox/ws/playwright.d.ts +1 -1
- package/build/routes/firefox/ws/playwright.js +2 -2
- package/build/routes/management/http/active.get.d.ts +1 -1
- package/build/routes/management/http/active.get.js +3 -1
- package/build/routes/management/http/config.get.d.ts +1 -1
- package/build/routes/management/http/config.get.js +2 -2
- package/build/routes/management/http/metrics-total.get.d.ts +1 -1
- package/build/routes/management/http/metrics-total.get.js +2 -2
- package/build/routes/management/http/metrics.get.d.ts +1 -1
- package/build/routes/management/http/metrics.get.js +2 -2
- package/build/routes/management/http/pressure.get.d.ts +1 -1
- package/build/routes/management/http/pressure.get.js +2 -2
- package/build/routes/management/http/sessions.get.d.ts +1 -1
- package/build/routes/management/http/sessions.get.js +2 -2
- package/build/routes/management/http/static.get.d.ts +1 -1
- package/build/routes/management/http/static.get.js +2 -2
- package/build/routes/webkit/ws/playwright.d.ts +1 -1
- package/build/routes/webkit/ws/playwright.js +2 -2
- package/build/server.d.ts +5 -5
- package/build/server.js +11 -11
- package/build/shared/browser.ws.d.ts +1 -1
- package/build/shared/browser.ws.js +3 -1
- package/build/shared/chromium.playwright.ws.d.ts +1 -1
- package/build/shared/chromium.playwright.ws.js +2 -2
- package/build/shared/chromium.ws.d.ts +1 -1
- package/build/shared/chromium.ws.js +3 -1
- package/build/shared/content.http.d.ts +1 -1
- package/build/shared/content.http.js +2 -2
- package/build/shared/download.http.d.ts +1 -1
- package/build/shared/download.http.js +60 -58
- package/build/shared/function.http.d.ts +1 -1
- package/build/shared/function.http.js +2 -2
- package/build/shared/json-list.http.d.ts +1 -1
- package/build/shared/json-list.http.js +2 -2
- package/build/shared/json-new.http.d.ts +1 -1
- package/build/shared/json-new.http.js +2 -2
- package/build/shared/json-protocol.http.d.ts +1 -1
- package/build/shared/json-protocol.http.js +2 -2
- package/build/shared/json-version.http.d.ts +1 -1
- package/build/shared/json-version.http.js +2 -2
- package/build/shared/page.ws.d.ts +1 -1
- package/build/shared/page.ws.js +3 -1
- package/build/shared/pdf.http.d.ts +1 -1
- package/build/shared/pdf.http.js +2 -2
- package/build/shared/performance.http.d.ts +1 -1
- package/build/shared/performance.http.js +2 -2
- package/build/shared/scrape.http.d.ts +1 -1
- package/build/shared/scrape.http.js +2 -2
- package/build/shared/screenshot.http.d.ts +1 -1
- package/build/shared/screenshot.http.js +2 -2
- package/build/shared/utils/function/client.d.ts +1 -1
- package/build/shared/utils/function/client.js +3 -1
- package/build/shim.d.ts +1 -1
- package/build/shim.js +2 -2
- package/build/token.d.ts +3 -3
- package/build/token.js +6 -6
- package/build/types.d.ts +4 -4
- package/build/webhooks.d.ts +2 -2
- package/build/webhooks.js +4 -4
- package/package.json +3 -3
- package/src/browserless.ts +6 -6
- package/src/browsers/chromium.cdp.ts +33 -23
- package/src/browsers/chromium.playwright.ts +28 -21
- package/src/browsers/firefox.playwright.ts +28 -21
- package/src/browsers/index.ts +32 -29
- package/src/browsers/webkit.playwright.ts +29 -22
- package/src/config.ts +166 -104
- package/src/file-system.ts +9 -9
- package/src/hooks.ts +4 -4
- package/src/limiter.ts +12 -12
- package/src/logger.ts +12 -12
- package/src/metrics.ts +23 -23
- package/src/monitoring.ts +9 -9
- package/src/router.ts +31 -31
- package/src/routes/firefox/ws/playwright.ts +3 -3
- package/src/routes/management/http/active.get.ts +3 -2
- package/src/routes/management/http/config.get.ts +2 -2
- package/src/routes/management/http/metrics-total.get.ts +2 -2
- package/src/routes/management/http/metrics.get.ts +2 -2
- package/src/routes/management/http/pressure.get.ts +2 -2
- package/src/routes/management/http/sessions.get.ts +2 -2
- package/src/routes/management/http/static.get.ts +3 -3
- package/src/routes/webkit/ws/playwright.ts +3 -3
- package/src/server.ts +14 -16
- package/src/shared/browser.ws.ts +4 -2
- package/src/shared/chromium.playwright.ws.ts +3 -3
- package/src/shared/chromium.ws.ts +4 -2
- package/src/shared/content.http.ts +3 -3
- package/src/shared/download.http.ts +4 -3
- package/src/shared/function.http.ts +3 -3
- package/src/shared/json-list.http.ts +2 -2
- package/src/shared/json-new.http.ts +2 -2
- package/src/shared/json-protocol.http.ts +2 -6
- package/src/shared/json-version.http.ts +2 -6
- package/src/shared/page.ws.ts +4 -2
- package/src/shared/pdf.http.ts +3 -3
- package/src/shared/performance.http.ts +3 -3
- package/src/shared/scrape.http.ts +3 -3
- package/src/shared/screenshot.http.ts +3 -3
- package/src/shared/utils/function/client.ts +3 -1
- package/src/shim.ts +2 -2
- package/src/token.ts +7 -7
- package/src/types.ts +7 -7
- package/src/webhooks.ts +4 -4
- package/static/docs/swagger.json +2 -2
- package/static/docs/swagger.min.json +1 -1
- package/static/function/client.js +3 -1
- 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
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
public
|
|
176
|
-
|
|
177
|
-
|
|
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
|
|
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
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
public
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
public
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
public
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
public
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
public
|
|
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
|
|
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
|
|
271
|
+
public getAllowCORS(): boolean {
|
|
272
|
+
return this.allowCors;
|
|
273
|
+
}
|
|
218
274
|
|
|
219
|
-
public
|
|
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
|
|
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
|
|
321
|
+
public getMetricsJSONPath() {
|
|
322
|
+
return this.metricsJSONPath;
|
|
323
|
+
}
|
|
266
324
|
|
|
267
|
-
public setPwVersions
|
|
268
|
-
this.pwVersions = versions;
|
|
269
|
-
}
|
|
325
|
+
public setPwVersions(versions: { [key: string]: string }) {
|
|
326
|
+
return (this.pwVersions = versions);
|
|
327
|
+
}
|
|
270
328
|
|
|
271
|
-
public loadPwVersion
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
421
|
+
public setCORSMaxAge(maxAge: number): number {
|
|
366
422
|
this.emit('corsMaxAge', maxAge);
|
|
367
423
|
return (this.corsMaxAge = maxAge);
|
|
368
|
-
}
|
|
369
|
-
public setFailedHealthURL
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
450
|
+
public setMetricsJSONPath(path: string) {
|
|
395
451
|
this.emit('metricsJSONPath', path);
|
|
396
452
|
return (this.metricsJSONPath = path);
|
|
397
|
-
}
|
|
453
|
+
}
|
|
398
454
|
|
|
399
|
-
public setPort
|
|
455
|
+
public setPort(port: number) {
|
|
400
456
|
this.emit('port', port);
|
|
401
457
|
return (this.port = port);
|
|
402
|
-
}
|
|
458
|
+
}
|
|
403
459
|
|
|
404
|
-
public setAllowFileProtocol
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
474
|
-
|
|
475
|
-
|
|
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
|
|
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
|
}
|
package/src/file-system.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
29
|
+
public trace(...messages: unknown[]) {
|
|
30
30
|
this._trace(this.reqInfo, ...messages);
|
|
31
|
-
}
|
|
31
|
+
}
|
|
32
32
|
|
|
33
|
-
public debug
|
|
33
|
+
public debug(...messages: unknown[]) {
|
|
34
34
|
this._debug(this.reqInfo, ...messages);
|
|
35
|
-
}
|
|
35
|
+
}
|
|
36
36
|
|
|
37
|
-
public info
|
|
37
|
+
public info(...messages: unknown[]) {
|
|
38
38
|
this._info(this.reqInfo, ...messages);
|
|
39
|
-
}
|
|
39
|
+
}
|
|
40
40
|
|
|
41
|
-
public warn
|
|
41
|
+
public warn(...messages: unknown[]) {
|
|
42
42
|
this._warn(this.reqInfo, ...messages);
|
|
43
|
-
}
|
|
43
|
+
}
|
|
44
44
|
|
|
45
|
-
public error
|
|
45
|
+
public error(...messages: unknown[]) {
|
|
46
46
|
this._error(this.reqInfo, ...messages);
|
|
47
|
-
}
|
|
47
|
+
}
|
|
48
48
|
|
|
49
|
-
public fatal
|
|
49
|
+
public fatal(...messages: unknown[]) {
|
|
50
50
|
this._fatal(this.reqInfo, ...messages);
|
|
51
|
-
}
|
|
51
|
+
}
|
|
52
52
|
}
|