@browserless.io/browserless 2.3.0-beta-2 → 2.4.0-beta-1
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/browserless.js +2 -0
- package/bin/scaffold/README.md +24 -1
- package/build/browserless.d.ts +2 -0
- package/build/browserless.js +8 -2
- package/build/data/selectors.json +1 -1
- package/build/routes/chrome/http/content.post.body.json +8 -8
- 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/chrome/tests/function.spec.js +32 -0
- 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/management/http/static.get.js +17 -11
- package/build/types.d.ts +9 -1
- package/build/types.js +10 -1
- package/package.json +3 -3
- package/src/browserless.ts +9 -0
- package/src/routes/chrome/tests/function.spec.ts +35 -0
- package/src/routes/management/http/static.get.ts +25 -15
- package/src/types.ts +9 -0
- package/static/docs/swagger.json +10 -10
- package/static/docs/swagger.min.json +9 -9
|
@@ -394,14 +394,14 @@
|
|
|
394
394
|
"length": {
|
|
395
395
|
"type": "number"
|
|
396
396
|
},
|
|
397
|
-
"__@toStringTag@
|
|
397
|
+
"__@toStringTag@10910": {
|
|
398
398
|
"type": "string",
|
|
399
399
|
"const": "Uint8Array"
|
|
400
400
|
}
|
|
401
401
|
},
|
|
402
402
|
"required": [
|
|
403
403
|
"BYTES_PER_ELEMENT",
|
|
404
|
-
"__@toStringTag@
|
|
404
|
+
"__@toStringTag@10910",
|
|
405
405
|
"buffer",
|
|
406
406
|
"byteLength",
|
|
407
407
|
"byteOffset",
|
|
@@ -436,13 +436,13 @@
|
|
|
436
436
|
"byteLength": {
|
|
437
437
|
"type": "number"
|
|
438
438
|
},
|
|
439
|
-
"__@toStringTag@
|
|
439
|
+
"__@toStringTag@10910": {
|
|
440
440
|
"type": "string"
|
|
441
441
|
}
|
|
442
442
|
},
|
|
443
443
|
"additionalProperties": false,
|
|
444
444
|
"required": [
|
|
445
|
-
"__@toStringTag@
|
|
445
|
+
"__@toStringTag@10910",
|
|
446
446
|
"byteLength"
|
|
447
447
|
]
|
|
448
448
|
},
|
|
@@ -452,18 +452,18 @@
|
|
|
452
452
|
"byteLength": {
|
|
453
453
|
"type": "number"
|
|
454
454
|
},
|
|
455
|
-
"__@species@
|
|
455
|
+
"__@species@11011": {
|
|
456
456
|
"$ref": "#/definitions/SharedArrayBuffer"
|
|
457
457
|
},
|
|
458
|
-
"__@toStringTag@
|
|
458
|
+
"__@toStringTag@10910": {
|
|
459
459
|
"type": "string",
|
|
460
460
|
"const": "SharedArrayBuffer"
|
|
461
461
|
}
|
|
462
462
|
},
|
|
463
463
|
"additionalProperties": false,
|
|
464
464
|
"required": [
|
|
465
|
-
"__@species@
|
|
466
|
-
"__@toStringTag@
|
|
465
|
+
"__@species@11011",
|
|
466
|
+
"__@toStringTag@10910",
|
|
467
467
|
"byteLength"
|
|
468
468
|
]
|
|
469
469
|
},
|
|
@@ -538,14 +538,14 @@
|
|
|
538
538
|
"length": {
|
|
539
539
|
"type": "number"
|
|
540
540
|
},
|
|
541
|
-
"__@toStringTag@
|
|
541
|
+
"__@toStringTag@97550": {
|
|
542
542
|
"type": "string",
|
|
543
543
|
"const": "Uint8Array"
|
|
544
544
|
}
|
|
545
545
|
},
|
|
546
546
|
"required": [
|
|
547
547
|
"BYTES_PER_ELEMENT",
|
|
548
|
-
"__@toStringTag@
|
|
548
|
+
"__@toStringTag@97550",
|
|
549
549
|
"buffer",
|
|
550
550
|
"byteLength",
|
|
551
551
|
"byteOffset",
|
|
@@ -580,13 +580,13 @@
|
|
|
580
580
|
"byteLength": {
|
|
581
581
|
"type": "number"
|
|
582
582
|
},
|
|
583
|
-
"__@toStringTag@
|
|
583
|
+
"__@toStringTag@97550": {
|
|
584
584
|
"type": "string"
|
|
585
585
|
}
|
|
586
586
|
},
|
|
587
587
|
"additionalProperties": false,
|
|
588
588
|
"required": [
|
|
589
|
-
"__@toStringTag@
|
|
589
|
+
"__@toStringTag@97550",
|
|
590
590
|
"byteLength"
|
|
591
591
|
]
|
|
592
592
|
},
|
|
@@ -596,18 +596,18 @@
|
|
|
596
596
|
"byteLength": {
|
|
597
597
|
"type": "number"
|
|
598
598
|
},
|
|
599
|
-
"__@species@
|
|
599
|
+
"__@species@97651": {
|
|
600
600
|
"$ref": "#/definitions/SharedArrayBuffer"
|
|
601
601
|
},
|
|
602
|
-
"__@toStringTag@
|
|
602
|
+
"__@toStringTag@97550": {
|
|
603
603
|
"type": "string",
|
|
604
604
|
"const": "SharedArrayBuffer"
|
|
605
605
|
}
|
|
606
606
|
},
|
|
607
607
|
"additionalProperties": false,
|
|
608
608
|
"required": [
|
|
609
|
-
"__@species@
|
|
610
|
-
"__@toStringTag@
|
|
609
|
+
"__@species@97651",
|
|
610
|
+
"__@toStringTag@97550",
|
|
611
611
|
"byteLength"
|
|
612
612
|
]
|
|
613
613
|
},
|
|
@@ -441,14 +441,14 @@
|
|
|
441
441
|
"length": {
|
|
442
442
|
"type": "number"
|
|
443
443
|
},
|
|
444
|
-
"__@toStringTag@
|
|
444
|
+
"__@toStringTag@108618": {
|
|
445
445
|
"type": "string",
|
|
446
446
|
"const": "Uint8Array"
|
|
447
447
|
}
|
|
448
448
|
},
|
|
449
449
|
"required": [
|
|
450
450
|
"BYTES_PER_ELEMENT",
|
|
451
|
-
"__@toStringTag@
|
|
451
|
+
"__@toStringTag@108618",
|
|
452
452
|
"buffer",
|
|
453
453
|
"byteLength",
|
|
454
454
|
"byteOffset",
|
|
@@ -483,13 +483,13 @@
|
|
|
483
483
|
"byteLength": {
|
|
484
484
|
"type": "number"
|
|
485
485
|
},
|
|
486
|
-
"__@toStringTag@
|
|
486
|
+
"__@toStringTag@108618": {
|
|
487
487
|
"type": "string"
|
|
488
488
|
}
|
|
489
489
|
},
|
|
490
490
|
"additionalProperties": false,
|
|
491
491
|
"required": [
|
|
492
|
-
"__@toStringTag@
|
|
492
|
+
"__@toStringTag@108618",
|
|
493
493
|
"byteLength"
|
|
494
494
|
]
|
|
495
495
|
},
|
|
@@ -499,18 +499,18 @@
|
|
|
499
499
|
"byteLength": {
|
|
500
500
|
"type": "number"
|
|
501
501
|
},
|
|
502
|
-
"__@species@
|
|
502
|
+
"__@species@108719": {
|
|
503
503
|
"$ref": "#/definitions/SharedArrayBuffer"
|
|
504
504
|
},
|
|
505
|
-
"__@toStringTag@
|
|
505
|
+
"__@toStringTag@108618": {
|
|
506
506
|
"type": "string",
|
|
507
507
|
"const": "SharedArrayBuffer"
|
|
508
508
|
}
|
|
509
509
|
},
|
|
510
510
|
"additionalProperties": false,
|
|
511
511
|
"required": [
|
|
512
|
-
"__@species@
|
|
513
|
-
"__@toStringTag@
|
|
512
|
+
"__@species@108719",
|
|
513
|
+
"__@toStringTag@108618",
|
|
514
514
|
"byteLength"
|
|
515
515
|
]
|
|
516
516
|
},
|
|
@@ -484,14 +484,14 @@
|
|
|
484
484
|
"length": {
|
|
485
485
|
"type": "number"
|
|
486
486
|
},
|
|
487
|
-
"__@toStringTag@
|
|
487
|
+
"__@toStringTag@119763": {
|
|
488
488
|
"type": "string",
|
|
489
489
|
"const": "Uint8Array"
|
|
490
490
|
}
|
|
491
491
|
},
|
|
492
492
|
"required": [
|
|
493
493
|
"BYTES_PER_ELEMENT",
|
|
494
|
-
"__@toStringTag@
|
|
494
|
+
"__@toStringTag@119763",
|
|
495
495
|
"buffer",
|
|
496
496
|
"byteLength",
|
|
497
497
|
"byteOffset",
|
|
@@ -526,13 +526,13 @@
|
|
|
526
526
|
"byteLength": {
|
|
527
527
|
"type": "number"
|
|
528
528
|
},
|
|
529
|
-
"__@toStringTag@
|
|
529
|
+
"__@toStringTag@119763": {
|
|
530
530
|
"type": "string"
|
|
531
531
|
}
|
|
532
532
|
},
|
|
533
533
|
"additionalProperties": false,
|
|
534
534
|
"required": [
|
|
535
|
-
"__@toStringTag@
|
|
535
|
+
"__@toStringTag@119763",
|
|
536
536
|
"byteLength"
|
|
537
537
|
]
|
|
538
538
|
},
|
|
@@ -542,18 +542,18 @@
|
|
|
542
542
|
"byteLength": {
|
|
543
543
|
"type": "number"
|
|
544
544
|
},
|
|
545
|
-
"__@species@
|
|
545
|
+
"__@species@119864": {
|
|
546
546
|
"$ref": "#/definitions/SharedArrayBuffer"
|
|
547
547
|
},
|
|
548
|
-
"__@toStringTag@
|
|
548
|
+
"__@toStringTag@119763": {
|
|
549
549
|
"type": "string",
|
|
550
550
|
"const": "SharedArrayBuffer"
|
|
551
551
|
}
|
|
552
552
|
},
|
|
553
553
|
"additionalProperties": false,
|
|
554
554
|
"required": [
|
|
555
|
-
"__@species@
|
|
556
|
-
"__@toStringTag@
|
|
555
|
+
"__@species@119864",
|
|
556
|
+
"__@toStringTag@119763",
|
|
557
557
|
"byteLength"
|
|
558
558
|
]
|
|
559
559
|
},
|
|
@@ -36,6 +36,38 @@ describe('/chrome/function API', function () {
|
|
|
36
36
|
expect(res.status).to.equal(200);
|
|
37
37
|
});
|
|
38
38
|
});
|
|
39
|
+
it('runs functions with "context"', async () => {
|
|
40
|
+
const config = new Config();
|
|
41
|
+
config.setToken('browserless');
|
|
42
|
+
const metrics = new Metrics();
|
|
43
|
+
await start({ config, metrics });
|
|
44
|
+
const body = {
|
|
45
|
+
code: `export default async function ({ page, context }) {
|
|
46
|
+
if (!!context.ok) {
|
|
47
|
+
return Promise.resolve({
|
|
48
|
+
data: "ok",
|
|
49
|
+
type: "application/text",
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return Promise.reject(new Error('Bad context!'));
|
|
53
|
+
}`,
|
|
54
|
+
context: {
|
|
55
|
+
ok: true,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
await fetch('http://localhost:3000/chrome/function?token=browserless', {
|
|
59
|
+
body: JSON.stringify(body),
|
|
60
|
+
headers: {
|
|
61
|
+
'content-type': 'application/json',
|
|
62
|
+
},
|
|
63
|
+
method: 'POST',
|
|
64
|
+
}).then(async (res) => {
|
|
65
|
+
const json = await res.json();
|
|
66
|
+
expect(json).to.have.property('data');
|
|
67
|
+
expect(json.data).to.equal('ok');
|
|
68
|
+
expect(res.status).to.equal(200);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
39
71
|
it('runs "application/javascript" functions', async () => {
|
|
40
72
|
const config = new Config();
|
|
41
73
|
config.setToken('browserless');
|
|
@@ -394,14 +394,14 @@
|
|
|
394
394
|
"length": {
|
|
395
395
|
"type": "number"
|
|
396
396
|
},
|
|
397
|
-
"__@toStringTag@
|
|
397
|
+
"__@toStringTag@141618": {
|
|
398
398
|
"type": "string",
|
|
399
399
|
"const": "Uint8Array"
|
|
400
400
|
}
|
|
401
401
|
},
|
|
402
402
|
"required": [
|
|
403
403
|
"BYTES_PER_ELEMENT",
|
|
404
|
-
"__@toStringTag@
|
|
404
|
+
"__@toStringTag@141618",
|
|
405
405
|
"buffer",
|
|
406
406
|
"byteLength",
|
|
407
407
|
"byteOffset",
|
|
@@ -436,13 +436,13 @@
|
|
|
436
436
|
"byteLength": {
|
|
437
437
|
"type": "number"
|
|
438
438
|
},
|
|
439
|
-
"__@toStringTag@
|
|
439
|
+
"__@toStringTag@141618": {
|
|
440
440
|
"type": "string"
|
|
441
441
|
}
|
|
442
442
|
},
|
|
443
443
|
"additionalProperties": false,
|
|
444
444
|
"required": [
|
|
445
|
-
"__@toStringTag@
|
|
445
|
+
"__@toStringTag@141618",
|
|
446
446
|
"byteLength"
|
|
447
447
|
]
|
|
448
448
|
},
|
|
@@ -452,18 +452,18 @@
|
|
|
452
452
|
"byteLength": {
|
|
453
453
|
"type": "number"
|
|
454
454
|
},
|
|
455
|
-
"__@species@
|
|
455
|
+
"__@species@141719": {
|
|
456
456
|
"$ref": "#/definitions/SharedArrayBuffer"
|
|
457
457
|
},
|
|
458
|
-
"__@toStringTag@
|
|
458
|
+
"__@toStringTag@141618": {
|
|
459
459
|
"type": "string",
|
|
460
460
|
"const": "SharedArrayBuffer"
|
|
461
461
|
}
|
|
462
462
|
},
|
|
463
463
|
"additionalProperties": false,
|
|
464
464
|
"required": [
|
|
465
|
-
"__@species@
|
|
466
|
-
"__@toStringTag@
|
|
465
|
+
"__@species@141719",
|
|
466
|
+
"__@toStringTag@141618",
|
|
467
467
|
"byteLength"
|
|
468
468
|
]
|
|
469
469
|
},
|
|
@@ -538,14 +538,14 @@
|
|
|
538
538
|
"length": {
|
|
539
539
|
"type": "number"
|
|
540
540
|
},
|
|
541
|
-
"__@toStringTag@
|
|
541
|
+
"__@toStringTag@217434": {
|
|
542
542
|
"type": "string",
|
|
543
543
|
"const": "Uint8Array"
|
|
544
544
|
}
|
|
545
545
|
},
|
|
546
546
|
"required": [
|
|
547
547
|
"BYTES_PER_ELEMENT",
|
|
548
|
-
"__@toStringTag@
|
|
548
|
+
"__@toStringTag@217434",
|
|
549
549
|
"buffer",
|
|
550
550
|
"byteLength",
|
|
551
551
|
"byteOffset",
|
|
@@ -580,13 +580,13 @@
|
|
|
580
580
|
"byteLength": {
|
|
581
581
|
"type": "number"
|
|
582
582
|
},
|
|
583
|
-
"__@toStringTag@
|
|
583
|
+
"__@toStringTag@217434": {
|
|
584
584
|
"type": "string"
|
|
585
585
|
}
|
|
586
586
|
},
|
|
587
587
|
"additionalProperties": false,
|
|
588
588
|
"required": [
|
|
589
|
-
"__@toStringTag@
|
|
589
|
+
"__@toStringTag@217434",
|
|
590
590
|
"byteLength"
|
|
591
591
|
]
|
|
592
592
|
},
|
|
@@ -596,18 +596,18 @@
|
|
|
596
596
|
"byteLength": {
|
|
597
597
|
"type": "number"
|
|
598
598
|
},
|
|
599
|
-
"__@species@
|
|
599
|
+
"__@species@217535": {
|
|
600
600
|
"$ref": "#/definitions/SharedArrayBuffer"
|
|
601
601
|
},
|
|
602
|
-
"__@toStringTag@
|
|
602
|
+
"__@toStringTag@217434": {
|
|
603
603
|
"type": "string",
|
|
604
604
|
"const": "SharedArrayBuffer"
|
|
605
605
|
}
|
|
606
606
|
},
|
|
607
607
|
"additionalProperties": false,
|
|
608
608
|
"required": [
|
|
609
|
-
"__@species@
|
|
610
|
-
"__@toStringTag@
|
|
609
|
+
"__@species@217535",
|
|
610
|
+
"__@toStringTag@217434",
|
|
611
611
|
"byteLength"
|
|
612
612
|
]
|
|
613
613
|
},
|
|
@@ -441,14 +441,14 @@
|
|
|
441
441
|
"length": {
|
|
442
442
|
"type": "number"
|
|
443
443
|
},
|
|
444
|
-
"__@toStringTag@
|
|
444
|
+
"__@toStringTag@228499": {
|
|
445
445
|
"type": "string",
|
|
446
446
|
"const": "Uint8Array"
|
|
447
447
|
}
|
|
448
448
|
},
|
|
449
449
|
"required": [
|
|
450
450
|
"BYTES_PER_ELEMENT",
|
|
451
|
-
"__@toStringTag@
|
|
451
|
+
"__@toStringTag@228499",
|
|
452
452
|
"buffer",
|
|
453
453
|
"byteLength",
|
|
454
454
|
"byteOffset",
|
|
@@ -483,13 +483,13 @@
|
|
|
483
483
|
"byteLength": {
|
|
484
484
|
"type": "number"
|
|
485
485
|
},
|
|
486
|
-
"__@toStringTag@
|
|
486
|
+
"__@toStringTag@228499": {
|
|
487
487
|
"type": "string"
|
|
488
488
|
}
|
|
489
489
|
},
|
|
490
490
|
"additionalProperties": false,
|
|
491
491
|
"required": [
|
|
492
|
-
"__@toStringTag@
|
|
492
|
+
"__@toStringTag@228499",
|
|
493
493
|
"byteLength"
|
|
494
494
|
]
|
|
495
495
|
},
|
|
@@ -499,18 +499,18 @@
|
|
|
499
499
|
"byteLength": {
|
|
500
500
|
"type": "number"
|
|
501
501
|
},
|
|
502
|
-
"__@species@
|
|
502
|
+
"__@species@228600": {
|
|
503
503
|
"$ref": "#/definitions/SharedArrayBuffer"
|
|
504
504
|
},
|
|
505
|
-
"__@toStringTag@
|
|
505
|
+
"__@toStringTag@228499": {
|
|
506
506
|
"type": "string",
|
|
507
507
|
"const": "SharedArrayBuffer"
|
|
508
508
|
}
|
|
509
509
|
},
|
|
510
510
|
"additionalProperties": false,
|
|
511
511
|
"required": [
|
|
512
|
-
"__@species@
|
|
513
|
-
"__@toStringTag@
|
|
512
|
+
"__@species@228600",
|
|
513
|
+
"__@toStringTag@228499",
|
|
514
514
|
"byteLength"
|
|
515
515
|
]
|
|
516
516
|
},
|
|
@@ -484,14 +484,14 @@
|
|
|
484
484
|
"length": {
|
|
485
485
|
"type": "number"
|
|
486
486
|
},
|
|
487
|
-
"__@toStringTag@
|
|
487
|
+
"__@toStringTag@239641": {
|
|
488
488
|
"type": "string",
|
|
489
489
|
"const": "Uint8Array"
|
|
490
490
|
}
|
|
491
491
|
},
|
|
492
492
|
"required": [
|
|
493
493
|
"BYTES_PER_ELEMENT",
|
|
494
|
-
"__@toStringTag@
|
|
494
|
+
"__@toStringTag@239641",
|
|
495
495
|
"buffer",
|
|
496
496
|
"byteLength",
|
|
497
497
|
"byteOffset",
|
|
@@ -526,13 +526,13 @@
|
|
|
526
526
|
"byteLength": {
|
|
527
527
|
"type": "number"
|
|
528
528
|
},
|
|
529
|
-
"__@toStringTag@
|
|
529
|
+
"__@toStringTag@239641": {
|
|
530
530
|
"type": "string"
|
|
531
531
|
}
|
|
532
532
|
},
|
|
533
533
|
"additionalProperties": false,
|
|
534
534
|
"required": [
|
|
535
|
-
"__@toStringTag@
|
|
535
|
+
"__@toStringTag@239641",
|
|
536
536
|
"byteLength"
|
|
537
537
|
]
|
|
538
538
|
},
|
|
@@ -542,18 +542,18 @@
|
|
|
542
542
|
"byteLength": {
|
|
543
543
|
"type": "number"
|
|
544
544
|
},
|
|
545
|
-
"__@species@
|
|
545
|
+
"__@species@239742": {
|
|
546
546
|
"$ref": "#/definitions/SharedArrayBuffer"
|
|
547
547
|
},
|
|
548
|
-
"__@toStringTag@
|
|
548
|
+
"__@toStringTag@239641": {
|
|
549
549
|
"type": "string",
|
|
550
550
|
"const": "SharedArrayBuffer"
|
|
551
551
|
}
|
|
552
552
|
},
|
|
553
553
|
"additionalProperties": false,
|
|
554
554
|
"required": [
|
|
555
|
-
"__@species@
|
|
556
|
-
"__@toStringTag@
|
|
555
|
+
"__@species@239742",
|
|
556
|
+
"__@toStringTag@239641",
|
|
557
557
|
"byteLength"
|
|
558
558
|
]
|
|
559
559
|
},
|
|
@@ -38,26 +38,32 @@ export default class StaticGetRoute extends HTTPRoute {
|
|
|
38
38
|
return streamFile(verbose, res, fileCache.path, fileCache.contentType);
|
|
39
39
|
}
|
|
40
40
|
const config = this.config();
|
|
41
|
+
const sdkDir = this.staticSDKDir();
|
|
41
42
|
const file = path.join(config.getStatic(), pathname);
|
|
42
43
|
const indexFile = path.join(file, 'index.html');
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
const locations = [file, indexFile];
|
|
45
|
+
if (sdkDir) {
|
|
46
|
+
const sdkPath = path.join(sdkDir, pathname);
|
|
47
|
+
locations.push(...[sdkPath, path.join(sdkPath, 'index.html')]);
|
|
48
|
+
}
|
|
49
|
+
const foundFilePaths = (await Promise.all(locations.map((l) => fileExists(l).then((e) => (e ? l : undefined))))).filter((_) => !!_);
|
|
50
|
+
if (!foundFilePaths.length) {
|
|
48
51
|
throw new NotFound(`No route or file found for resource ${req.method}: ${pathname}`);
|
|
49
52
|
}
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
if (foundFilePaths.length > 1) {
|
|
54
|
+
debug(`Multiple files found for request to "${pathname}". Only the first file is served, so please name your files uniquely.`);
|
|
55
|
+
}
|
|
56
|
+
const [foundFilePath] = foundFilePaths;
|
|
57
|
+
verbose(`Found new file "${foundFilePath}", caching path and serving`);
|
|
58
|
+
const contentType = mimeTypes.get(path.extname(foundFilePath));
|
|
52
59
|
if (contentType) {
|
|
53
60
|
res.setHeader('Content-Type', contentType);
|
|
54
61
|
}
|
|
55
|
-
// Cache the
|
|
56
|
-
// do stat checks again when requests come back
|
|
62
|
+
// Cache the file as being found so we don't have to call 'stat'
|
|
57
63
|
pathMap.set(pathname, {
|
|
58
64
|
contentType,
|
|
59
|
-
path:
|
|
65
|
+
path: foundFilePath,
|
|
60
66
|
});
|
|
61
|
-
return streamFile(verbose, res,
|
|
67
|
+
return streamFile(verbose, res, foundFilePath, contentType);
|
|
62
68
|
};
|
|
63
69
|
}
|
package/build/types.d.ts
CHANGED
|
@@ -55,7 +55,8 @@ declare abstract class Route {
|
|
|
55
55
|
protected _debug: Browserless['debug'];
|
|
56
56
|
protected _metrics: Browserless['metrics'];
|
|
57
57
|
protected _monitoring: Browserless['monitoring'];
|
|
58
|
-
|
|
58
|
+
protected _staticSDKDir: Browserless['staticSDKDir'];
|
|
59
|
+
constructor(_browserManager: Browserless['browserManager'], _config: Browserless['config'], _fileSystem: Browserless['fileSystem'], _debug: Browserless['debug'], _metrics: Browserless['metrics'], _monitoring: Browserless['monitoring'], _staticSDKDir: Browserless['staticSDKDir']);
|
|
59
60
|
/**
|
|
60
61
|
* A unique name to identify this route. Used in downstream
|
|
61
62
|
* SDKs to potentially remove or disable.
|
|
@@ -134,6 +135,13 @@ declare abstract class Route {
|
|
|
134
135
|
* @returns Monitor
|
|
135
136
|
*/
|
|
136
137
|
monitoring: () => import("@browserless.io/browserless").Monitoring;
|
|
138
|
+
/**
|
|
139
|
+
* When running in an SDK environment, this returns the fully-qualified
|
|
140
|
+
* directory of that static directory. When "null" then no SDK directory
|
|
141
|
+
* has been set.
|
|
142
|
+
* @returns {string | null} The full path location of the SDK's static directory
|
|
143
|
+
*/
|
|
144
|
+
staticSDKDir: () => string | null;
|
|
137
145
|
/**
|
|
138
146
|
* The HTTP path that this route handles, eg '/my-route' OR an
|
|
139
147
|
* array of paths that this route can handle.
|
package/build/types.js
CHANGED
|
@@ -5,13 +5,15 @@ class Route {
|
|
|
5
5
|
_debug;
|
|
6
6
|
_metrics;
|
|
7
7
|
_monitoring;
|
|
8
|
-
|
|
8
|
+
_staticSDKDir;
|
|
9
|
+
constructor(_browserManager, _config, _fileSystem, _debug, _metrics, _monitoring, _staticSDKDir) {
|
|
9
10
|
this._browserManager = _browserManager;
|
|
10
11
|
this._config = _config;
|
|
11
12
|
this._fileSystem = _fileSystem;
|
|
12
13
|
this._debug = _debug;
|
|
13
14
|
this._metrics = _metrics;
|
|
14
15
|
this._monitoring = _monitoring;
|
|
16
|
+
this._staticSDKDir = _staticSDKDir;
|
|
15
17
|
}
|
|
16
18
|
/**
|
|
17
19
|
* A boolean, or a function that returns a boolean, on
|
|
@@ -86,6 +88,13 @@ class Route {
|
|
|
86
88
|
* @returns Monitor
|
|
87
89
|
*/
|
|
88
90
|
monitoring = () => this._monitoring;
|
|
91
|
+
/**
|
|
92
|
+
* When running in an SDK environment, this returns the fully-qualified
|
|
93
|
+
* directory of that static directory. When "null" then no SDK directory
|
|
94
|
+
* has been set.
|
|
95
|
+
* @returns {string | null} The full path location of the SDK's static directory
|
|
96
|
+
*/
|
|
97
|
+
staticSDKDir = () => this._staticSDKDir;
|
|
89
98
|
}
|
|
90
99
|
/**
|
|
91
100
|
* A primitive HTTP-based route that doesn't require a
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@browserless.io/browserless",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0-beta-1",
|
|
4
4
|
"license": "SSPL",
|
|
5
5
|
"description": "The browserless platform",
|
|
6
6
|
"author": "browserless.io",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"http-proxy": "^1.18.1",
|
|
58
58
|
"lighthouse": "^11.1.0",
|
|
59
59
|
"micromatch": "^4.0.4",
|
|
60
|
-
"playwright-core": "^1.42.
|
|
60
|
+
"playwright-core": "^1.42.1",
|
|
61
61
|
"puppeteer-core": "^22.3.0",
|
|
62
62
|
"puppeteer-extra": "^3.3.6",
|
|
63
63
|
"puppeteer-extra-plugin-stealth": "^2.11.2",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"@types/http-proxy": "^1.17.14",
|
|
72
72
|
"@types/micromatch": "^4.0.6",
|
|
73
73
|
"@types/mocha": "^10.0.6",
|
|
74
|
-
"@types/node": "^20.11.
|
|
74
|
+
"@types/node": "^20.11.24",
|
|
75
75
|
"@types/sinon": "^17.0.3",
|
|
76
76
|
"@typescript-eslint/eslint-plugin": "^7.1.0",
|
|
77
77
|
"@typescript-eslint/parser": "^7.1.0",
|
package/src/browserless.ts
CHANGED
|
@@ -53,6 +53,7 @@ export class Browserless {
|
|
|
53
53
|
protected router: Router;
|
|
54
54
|
protected token: Token;
|
|
55
55
|
protected webhooks: WebHooks;
|
|
56
|
+
protected staticSDKDir: string | null = null;
|
|
56
57
|
|
|
57
58
|
disabledRouteNames: string[] = [];
|
|
58
59
|
webSocketRouteFiles: string[] = [];
|
|
@@ -149,6 +150,10 @@ export class Browserless {
|
|
|
149
150
|
return this.disabledRouteNames.some((name) => name === route.name);
|
|
150
151
|
}
|
|
151
152
|
|
|
153
|
+
public setStaticSDKDir(dir: string) {
|
|
154
|
+
this.staticSDKDir = dir;
|
|
155
|
+
}
|
|
156
|
+
|
|
152
157
|
public disableRoutes(...routeNames: string[]) {
|
|
153
158
|
this.disabledRouteNames.push(...routeNames);
|
|
154
159
|
}
|
|
@@ -226,6 +231,7 @@ export class Browserless {
|
|
|
226
231
|
logger,
|
|
227
232
|
this.metrics,
|
|
228
233
|
this.monitoring,
|
|
234
|
+
this.staticSDKDir,
|
|
229
235
|
);
|
|
230
236
|
|
|
231
237
|
if (!this.routeIsDisabled(route)) {
|
|
@@ -236,6 +242,7 @@ export class Browserless {
|
|
|
236
242
|
route.monitoring = () => this.monitoring;
|
|
237
243
|
route.fileSystem = () => this.fileSystem;
|
|
238
244
|
route.debug = () => logger;
|
|
245
|
+
route.staticSDKDir = () => this.staticSDKDir;
|
|
239
246
|
|
|
240
247
|
httpRoutes.push(route);
|
|
241
248
|
}
|
|
@@ -277,6 +284,7 @@ export class Browserless {
|
|
|
277
284
|
logger,
|
|
278
285
|
this.metrics,
|
|
279
286
|
this.monitoring,
|
|
287
|
+
this.staticSDKDir,
|
|
280
288
|
);
|
|
281
289
|
|
|
282
290
|
if (!this.routeIsDisabled(route)) {
|
|
@@ -286,6 +294,7 @@ export class Browserless {
|
|
|
286
294
|
route.monitoring = () => this.monitoring;
|
|
287
295
|
route.fileSystem = () => this.fileSystem;
|
|
288
296
|
route.debug = () => logger;
|
|
297
|
+
route.staticSDKDir = () => this.staticSDKDir;
|
|
289
298
|
|
|
290
299
|
wsRoutes.push(route);
|
|
291
300
|
}
|