@browserless.io/browserless 2.0.0-beta-7 → 2.1.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/README.md +10 -6
- package/bin/browserless.js +4 -4
- package/bin/scaffold/README.md +7 -7
- package/bin/scaffold/tsconfig.json +1 -1
- package/browser.json +3 -3
- package/build/browsers/cdp-chromium.js +1 -2
- package/build/browsers/index.d.ts +9 -0
- package/build/browsers/index.js +24 -0
- package/build/browsers/playwright-chromium.js +1 -2
- package/build/browsers/playwright-firefox.js +1 -2
- package/build/browsers/playwright-webkit.js +1 -2
- package/build/config.d.ts +9 -0
- package/build/config.js +15 -0
- package/build/data/selectors.json +1 -1
- package/build/file-system.spec.js +1 -1
- package/build/http.d.ts +1 -0
- package/build/http.js +1 -0
- package/build/routes/chromium/http/content-post.body.json +8 -8
- package/build/routes/chromium/http/json-version-get.d.ts +15 -0
- package/build/routes/chromium/http/json-version-get.js +30 -0
- package/build/routes/chromium/http/json-version-get.response.json +37 -0
- 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/chromium/tests/json-version.spec.d.ts +1 -0
- package/build/routes/chromium/tests/json-version.spec.js +37 -0
- package/build/utils.js +1 -1
- package/package.json +10 -11
- package/src/browsers/cdp-chromium.ts +2 -3
- package/src/browsers/index.ts +40 -2
- package/src/browsers/playwright-chromium.ts +2 -3
- package/src/browsers/playwright-firefox.ts +2 -3
- package/src/browsers/playwright-webkit.ts +2 -3
- package/src/config.ts +17 -0
- package/src/file-system.spec.ts +1 -1
- package/src/http.ts +1 -0
- package/src/routes/chromium/http/json-version-get.ts +55 -0
- package/src/routes/chromium/tests/json-version.spec.ts +52 -0
- package/src/utils.ts +1 -1
- package/static/docs/swagger.json +99 -10
|
@@ -2,7 +2,7 @@ import { Config, FileSystem, sleep } from '@browserless.io/browserless';
|
|
|
2
2
|
import { readFile, unlink } from 'fs/promises';
|
|
3
3
|
import { expect } from 'chai';
|
|
4
4
|
const filePath = '/tmp/_browserless_test_fs_';
|
|
5
|
-
describe
|
|
5
|
+
describe('File-System', () => {
|
|
6
6
|
afterEach(async () => unlink(filePath));
|
|
7
7
|
it('saves and encodes files', async () => {
|
|
8
8
|
const mySecretContents = 'pony-foo';
|
package/build/http.d.ts
CHANGED
package/build/http.js
CHANGED
|
@@ -83,6 +83,7 @@ export var HTTPRoutes;
|
|
|
83
83
|
HTTPRoutes["content"] = "/content";
|
|
84
84
|
HTTPRoutes["download"] = "/download";
|
|
85
85
|
HTTPRoutes["function"] = "/function";
|
|
86
|
+
HTTPRoutes["jsonVersion"] = "/json/version";
|
|
86
87
|
HTTPRoutes["pdf"] = "/pdf";
|
|
87
88
|
HTTPRoutes["performance"] = "/performance";
|
|
88
89
|
HTTPRoutes["scrape"] = "/scrape";
|
|
@@ -398,14 +398,14 @@
|
|
|
398
398
|
"length": {
|
|
399
399
|
"type": "number"
|
|
400
400
|
},
|
|
401
|
-
"__@toStringTag@
|
|
401
|
+
"__@toStringTag@10755": {
|
|
402
402
|
"type": "string",
|
|
403
403
|
"const": "Uint8Array"
|
|
404
404
|
}
|
|
405
405
|
},
|
|
406
406
|
"required": [
|
|
407
407
|
"BYTES_PER_ELEMENT",
|
|
408
|
-
"__@toStringTag@
|
|
408
|
+
"__@toStringTag@10755",
|
|
409
409
|
"buffer",
|
|
410
410
|
"byteLength",
|
|
411
411
|
"byteOffset",
|
|
@@ -440,13 +440,13 @@
|
|
|
440
440
|
"byteLength": {
|
|
441
441
|
"type": "number"
|
|
442
442
|
},
|
|
443
|
-
"__@toStringTag@
|
|
443
|
+
"__@toStringTag@10755": {
|
|
444
444
|
"type": "string"
|
|
445
445
|
}
|
|
446
446
|
},
|
|
447
447
|
"additionalProperties": false,
|
|
448
448
|
"required": [
|
|
449
|
-
"__@toStringTag@
|
|
449
|
+
"__@toStringTag@10755",
|
|
450
450
|
"byteLength"
|
|
451
451
|
]
|
|
452
452
|
},
|
|
@@ -456,18 +456,18 @@
|
|
|
456
456
|
"byteLength": {
|
|
457
457
|
"type": "number"
|
|
458
458
|
},
|
|
459
|
-
"__@species@
|
|
459
|
+
"__@species@10856": {
|
|
460
460
|
"$ref": "#/definitions/SharedArrayBuffer"
|
|
461
461
|
},
|
|
462
|
-
"__@toStringTag@
|
|
462
|
+
"__@toStringTag@10755": {
|
|
463
463
|
"type": "string",
|
|
464
464
|
"const": "SharedArrayBuffer"
|
|
465
465
|
}
|
|
466
466
|
},
|
|
467
467
|
"additionalProperties": false,
|
|
468
468
|
"required": [
|
|
469
|
-
"__@species@
|
|
470
|
-
"__@toStringTag@
|
|
469
|
+
"__@species@10856",
|
|
470
|
+
"__@toStringTag@10755",
|
|
471
471
|
"byteLength"
|
|
472
472
|
]
|
|
473
473
|
},
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { APITags, BrowserManager, HTTPRoutes, HTTPRoute, Methods, Request, Response, UnwrapPromise, contentTypes } from '@browserless.io/browserless';
|
|
2
|
+
export type ResponseSchema = UnwrapPromise<ReturnType<BrowserManager['getVersionJSON']>>;
|
|
3
|
+
export default class GetJSONVersion extends HTTPRoute {
|
|
4
|
+
accepts: contentTypes[];
|
|
5
|
+
auth: boolean;
|
|
6
|
+
browser: null;
|
|
7
|
+
concurrency: boolean;
|
|
8
|
+
contentTypes: contentTypes[];
|
|
9
|
+
description: string;
|
|
10
|
+
method: Methods;
|
|
11
|
+
path: HTTPRoutes;
|
|
12
|
+
tags: APITags[];
|
|
13
|
+
private cachedJSON;
|
|
14
|
+
handler: (req: Request, res: Response) => Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { APITags, HTTPRoutes, HTTPRoute, Methods, contentTypes, jsonResponse, writeResponse, } from '@browserless.io/browserless';
|
|
2
|
+
export default class GetJSONVersion extends HTTPRoute {
|
|
3
|
+
accepts = [contentTypes.any];
|
|
4
|
+
auth = true;
|
|
5
|
+
browser = null;
|
|
6
|
+
concurrency = false;
|
|
7
|
+
contentTypes = [contentTypes.json];
|
|
8
|
+
description = `Returns a JSON payload that acts as a pass-through to the DevTools /json/version protocol in Chrome.`;
|
|
9
|
+
method = Methods.get;
|
|
10
|
+
path = HTTPRoutes.jsonVersion;
|
|
11
|
+
tags = [APITags.browserAPI];
|
|
12
|
+
cachedJSON;
|
|
13
|
+
handler = async (req, res) => {
|
|
14
|
+
const baseUrl = req.parsed.host;
|
|
15
|
+
const protocol = req.parsed.protocol.includes('s') ? 'wss' : 'ws';
|
|
16
|
+
const browserManager = this.browserManager();
|
|
17
|
+
try {
|
|
18
|
+
if (!this.cachedJSON) {
|
|
19
|
+
this.cachedJSON = {
|
|
20
|
+
...(await browserManager.getVersionJSON()),
|
|
21
|
+
webSocketDebuggerUrl: `${protocol}://${baseUrl}`,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return jsonResponse(res, 200, this.cachedJSON);
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
return writeResponse(res, 500, 'There was an error handling your request', contentTypes.text);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "object",
|
|
3
|
+
"properties": {
|
|
4
|
+
"Browser": {
|
|
5
|
+
"type": "string"
|
|
6
|
+
},
|
|
7
|
+
"Debugger-Version": {
|
|
8
|
+
"type": "string"
|
|
9
|
+
},
|
|
10
|
+
"Protocol-Version": {
|
|
11
|
+
"type": "string"
|
|
12
|
+
},
|
|
13
|
+
"User-Agent": {
|
|
14
|
+
"type": "string"
|
|
15
|
+
},
|
|
16
|
+
"V8-Version": {
|
|
17
|
+
"type": "string"
|
|
18
|
+
},
|
|
19
|
+
"WebKit-Version": {
|
|
20
|
+
"type": "string"
|
|
21
|
+
},
|
|
22
|
+
"webSocketDebuggerUrl": {
|
|
23
|
+
"type": "string"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"additionalProperties": false,
|
|
27
|
+
"required": [
|
|
28
|
+
"Browser",
|
|
29
|
+
"Debugger-Version",
|
|
30
|
+
"Protocol-Version",
|
|
31
|
+
"User-Agent",
|
|
32
|
+
"V8-Version",
|
|
33
|
+
"WebKit-Version",
|
|
34
|
+
"webSocketDebuggerUrl"
|
|
35
|
+
],
|
|
36
|
+
"$schema": "http://json-schema.org/draft-07/schema#"
|
|
37
|
+
}
|
|
@@ -538,14 +538,14 @@
|
|
|
538
538
|
"length": {
|
|
539
539
|
"type": "number"
|
|
540
540
|
},
|
|
541
|
-
"__@toStringTag@
|
|
541
|
+
"__@toStringTag@53628": {
|
|
542
542
|
"type": "string",
|
|
543
543
|
"const": "Uint8Array"
|
|
544
544
|
}
|
|
545
545
|
},
|
|
546
546
|
"required": [
|
|
547
547
|
"BYTES_PER_ELEMENT",
|
|
548
|
-
"__@toStringTag@
|
|
548
|
+
"__@toStringTag@53628",
|
|
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@53628": {
|
|
584
584
|
"type": "string"
|
|
585
585
|
}
|
|
586
586
|
},
|
|
587
587
|
"additionalProperties": false,
|
|
588
588
|
"required": [
|
|
589
|
-
"__@toStringTag@
|
|
589
|
+
"__@toStringTag@53628",
|
|
590
590
|
"byteLength"
|
|
591
591
|
]
|
|
592
592
|
},
|
|
@@ -596,18 +596,18 @@
|
|
|
596
596
|
"byteLength": {
|
|
597
597
|
"type": "number"
|
|
598
598
|
},
|
|
599
|
-
"__@species@
|
|
599
|
+
"__@species@53729": {
|
|
600
600
|
"$ref": "#/definitions/SharedArrayBuffer"
|
|
601
601
|
},
|
|
602
|
-
"__@toStringTag@
|
|
602
|
+
"__@toStringTag@53628": {
|
|
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@53729",
|
|
610
|
+
"__@toStringTag@53628",
|
|
611
611
|
"byteLength"
|
|
612
612
|
]
|
|
613
613
|
},
|
|
@@ -445,14 +445,14 @@
|
|
|
445
445
|
"length": {
|
|
446
446
|
"type": "number"
|
|
447
447
|
},
|
|
448
|
-
"__@toStringTag@
|
|
448
|
+
"__@toStringTag@64541": {
|
|
449
449
|
"type": "string",
|
|
450
450
|
"const": "Uint8Array"
|
|
451
451
|
}
|
|
452
452
|
},
|
|
453
453
|
"required": [
|
|
454
454
|
"BYTES_PER_ELEMENT",
|
|
455
|
-
"__@toStringTag@
|
|
455
|
+
"__@toStringTag@64541",
|
|
456
456
|
"buffer",
|
|
457
457
|
"byteLength",
|
|
458
458
|
"byteOffset",
|
|
@@ -487,13 +487,13 @@
|
|
|
487
487
|
"byteLength": {
|
|
488
488
|
"type": "number"
|
|
489
489
|
},
|
|
490
|
-
"__@toStringTag@
|
|
490
|
+
"__@toStringTag@64541": {
|
|
491
491
|
"type": "string"
|
|
492
492
|
}
|
|
493
493
|
},
|
|
494
494
|
"additionalProperties": false,
|
|
495
495
|
"required": [
|
|
496
|
-
"__@toStringTag@
|
|
496
|
+
"__@toStringTag@64541",
|
|
497
497
|
"byteLength"
|
|
498
498
|
]
|
|
499
499
|
},
|
|
@@ -503,18 +503,18 @@
|
|
|
503
503
|
"byteLength": {
|
|
504
504
|
"type": "number"
|
|
505
505
|
},
|
|
506
|
-
"__@species@
|
|
506
|
+
"__@species@64642": {
|
|
507
507
|
"$ref": "#/definitions/SharedArrayBuffer"
|
|
508
508
|
},
|
|
509
|
-
"__@toStringTag@
|
|
509
|
+
"__@toStringTag@64541": {
|
|
510
510
|
"type": "string",
|
|
511
511
|
"const": "SharedArrayBuffer"
|
|
512
512
|
}
|
|
513
513
|
},
|
|
514
514
|
"additionalProperties": false,
|
|
515
515
|
"required": [
|
|
516
|
-
"__@species@
|
|
517
|
-
"__@toStringTag@
|
|
516
|
+
"__@species@64642",
|
|
517
|
+
"__@toStringTag@64541",
|
|
518
518
|
"byteLength"
|
|
519
519
|
]
|
|
520
520
|
},
|
|
@@ -488,14 +488,14 @@
|
|
|
488
488
|
"length": {
|
|
489
489
|
"type": "number"
|
|
490
490
|
},
|
|
491
|
-
"__@toStringTag@
|
|
491
|
+
"__@toStringTag@75532": {
|
|
492
492
|
"type": "string",
|
|
493
493
|
"const": "Uint8Array"
|
|
494
494
|
}
|
|
495
495
|
},
|
|
496
496
|
"required": [
|
|
497
497
|
"BYTES_PER_ELEMENT",
|
|
498
|
-
"__@toStringTag@
|
|
498
|
+
"__@toStringTag@75532",
|
|
499
499
|
"buffer",
|
|
500
500
|
"byteLength",
|
|
501
501
|
"byteOffset",
|
|
@@ -530,13 +530,13 @@
|
|
|
530
530
|
"byteLength": {
|
|
531
531
|
"type": "number"
|
|
532
532
|
},
|
|
533
|
-
"__@toStringTag@
|
|
533
|
+
"__@toStringTag@75532": {
|
|
534
534
|
"type": "string"
|
|
535
535
|
}
|
|
536
536
|
},
|
|
537
537
|
"additionalProperties": false,
|
|
538
538
|
"required": [
|
|
539
|
-
"__@toStringTag@
|
|
539
|
+
"__@toStringTag@75532",
|
|
540
540
|
"byteLength"
|
|
541
541
|
]
|
|
542
542
|
},
|
|
@@ -546,18 +546,18 @@
|
|
|
546
546
|
"byteLength": {
|
|
547
547
|
"type": "number"
|
|
548
548
|
},
|
|
549
|
-
"__@species@
|
|
549
|
+
"__@species@75633": {
|
|
550
550
|
"$ref": "#/definitions/SharedArrayBuffer"
|
|
551
551
|
},
|
|
552
|
-
"__@toStringTag@
|
|
552
|
+
"__@toStringTag@75532": {
|
|
553
553
|
"type": "string",
|
|
554
554
|
"const": "SharedArrayBuffer"
|
|
555
555
|
}
|
|
556
556
|
},
|
|
557
557
|
"additionalProperties": false,
|
|
558
558
|
"required": [
|
|
559
|
-
"__@species@
|
|
560
|
-
"__@toStringTag@
|
|
559
|
+
"__@species@75633",
|
|
560
|
+
"__@toStringTag@75532",
|
|
561
561
|
"byteLength"
|
|
562
562
|
]
|
|
563
563
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Browserless, Config, Metrics } from '@browserless.io/browserless';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
describe('/json/version API', function () {
|
|
4
|
+
let browserless;
|
|
5
|
+
const start = ({ config = new Config(), metrics = new Metrics(), } = {}) => {
|
|
6
|
+
browserless = new Browserless({ config, metrics });
|
|
7
|
+
return browserless.start();
|
|
8
|
+
};
|
|
9
|
+
afterEach(async () => {
|
|
10
|
+
await browserless.stop();
|
|
11
|
+
});
|
|
12
|
+
it('allows requests to /json/version', async () => {
|
|
13
|
+
const config = new Config();
|
|
14
|
+
config.setToken('browserless');
|
|
15
|
+
const metrics = new Metrics();
|
|
16
|
+
await start({ config, metrics });
|
|
17
|
+
const res = await fetch('http://localhost:3000/json/version?token=browserless');
|
|
18
|
+
const resJSON = await res.json();
|
|
19
|
+
[
|
|
20
|
+
'Browser',
|
|
21
|
+
'Protocol-Version',
|
|
22
|
+
'User-Agent',
|
|
23
|
+
'V8-Version',
|
|
24
|
+
'WebKit-Version',
|
|
25
|
+
'webSocketDebuggerUrl',
|
|
26
|
+
'Debugger-Version',
|
|
27
|
+
].forEach((k) => expect(resJSON).to.haveOwnProperty(k));
|
|
28
|
+
});
|
|
29
|
+
it('rejects unauthorized requests to /json/version', async () => {
|
|
30
|
+
const config = new Config();
|
|
31
|
+
config.setToken('browserless');
|
|
32
|
+
const metrics = new Metrics();
|
|
33
|
+
await start({ config, metrics });
|
|
34
|
+
const res = await fetch('http://localhost:3000/json/version?token=imabadboi');
|
|
35
|
+
expect(res.status).to.equal(401);
|
|
36
|
+
});
|
|
37
|
+
});
|
package/build/utils.js
CHANGED
|
@@ -27,7 +27,7 @@ export const jsonExtension = '.json';
|
|
|
27
27
|
export const jsExtension = '.js';
|
|
28
28
|
export const id = () => crypto.randomUUID();
|
|
29
29
|
export const createLogger = (domain) => {
|
|
30
|
-
return debug(`browserless:${domain}`);
|
|
30
|
+
return debug(`browserless.io:${domain}`);
|
|
31
31
|
};
|
|
32
32
|
const errorLog = createLogger('error');
|
|
33
33
|
export const dedent = (strings, ...values) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@browserless.io/browserless",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"license": "SSPL",
|
|
5
5
|
"description": "The browserless platform",
|
|
6
6
|
"author": "browserless.io",
|
|
@@ -51,18 +51,18 @@
|
|
|
51
51
|
"debug": "^4.3.2",
|
|
52
52
|
"del": "^7.0.0",
|
|
53
53
|
"enjoi": "^9.0.1",
|
|
54
|
-
"file-type": "^
|
|
54
|
+
"file-type": "^19.0.0",
|
|
55
55
|
"get-port": "^7.0.0",
|
|
56
56
|
"gradient-string": "^2.0.0",
|
|
57
57
|
"http-proxy": "^1.18.1",
|
|
58
58
|
"lighthouse": "^11.1.0",
|
|
59
59
|
"micromatch": "^4.0.4",
|
|
60
|
-
"playwright-core": "^1.
|
|
60
|
+
"playwright-core": "^1.41.1",
|
|
61
61
|
"puppeteer-core": "^21.6.1",
|
|
62
62
|
"puppeteer-extra": "^3.3.6",
|
|
63
63
|
"puppeteer-extra-plugin-stealth": "^2.11.2",
|
|
64
64
|
"queue": "^7.0.0",
|
|
65
|
-
"systeminformation": "^5.21.
|
|
65
|
+
"systeminformation": "^5.21.24"
|
|
66
66
|
},
|
|
67
67
|
"optionalDependencies": {
|
|
68
68
|
"@types/chai": "^4.3.11",
|
|
@@ -71,10 +71,10 @@
|
|
|
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.
|
|
75
|
-
"@types/sinon": "^17.0.
|
|
76
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
77
|
-
"@typescript-eslint/parser": "^6.
|
|
74
|
+
"@types/node": "^20.11.5",
|
|
75
|
+
"@types/sinon": "^17.0.3",
|
|
76
|
+
"@typescript-eslint/eslint-plugin": "^6.19.1",
|
|
77
|
+
"@typescript-eslint/parser": "^6.19.1",
|
|
78
78
|
"assert": "^2.0.0",
|
|
79
79
|
"chai": "^5.0.0",
|
|
80
80
|
"cross-env": "^7.0.3",
|
|
@@ -88,8 +88,7 @@
|
|
|
88
88
|
"marked": "^11.1.0",
|
|
89
89
|
"mocha": "^10.0.0",
|
|
90
90
|
"move-file": "^3.1.0",
|
|
91
|
-
"
|
|
92
|
-
"prettier": "^3.1.1",
|
|
91
|
+
"prettier": "^3.2.4",
|
|
93
92
|
"sinon": "^17.0.1",
|
|
94
93
|
"ts-node": "^10.9.2",
|
|
95
94
|
"typescript": "^5.3.3",
|
|
@@ -144,7 +143,7 @@
|
|
|
144
143
|
"multiple",
|
|
145
144
|
"single"
|
|
146
145
|
],
|
|
147
|
-
"allowSeparatedGroups":
|
|
146
|
+
"allowSeparatedGroups": true
|
|
148
147
|
}
|
|
149
148
|
]
|
|
150
149
|
}
|
|
@@ -319,12 +319,11 @@ export class CDPChromium extends EventEmitter {
|
|
|
319
319
|
return null;
|
|
320
320
|
}
|
|
321
321
|
|
|
322
|
+
const serverURL = new URL(this.config.getExternalWebSocketAddress());
|
|
322
323
|
const wsURL = new URL(this.browserWSEndpoint);
|
|
323
|
-
const serverURL = new URL(this.config.getExternalAddress());
|
|
324
|
-
|
|
325
324
|
wsURL.hostname = serverURL.hostname;
|
|
326
325
|
wsURL.port = serverURL.port;
|
|
327
|
-
|
|
326
|
+
|
|
328
327
|
if (token) {
|
|
329
328
|
wsURL.searchParams.set('token', token);
|
|
330
329
|
}
|
package/src/browsers/index.ts
CHANGED
|
@@ -82,6 +82,44 @@ export class BrowserManager {
|
|
|
82
82
|
return dataDirPath;
|
|
83
83
|
};
|
|
84
84
|
|
|
85
|
+
public getVersionJSON = async (): Promise<{
|
|
86
|
+
Browser: string;
|
|
87
|
+
'Debugger-Version': string;
|
|
88
|
+
'Protocol-Version': string;
|
|
89
|
+
'User-Agent': string;
|
|
90
|
+
'V8-Version': string;
|
|
91
|
+
'WebKit-Version': string;
|
|
92
|
+
webSocketDebuggerUrl: string;
|
|
93
|
+
}> => {
|
|
94
|
+
const browser = new CDPChromium({
|
|
95
|
+
blockAds: false,
|
|
96
|
+
config: this.config,
|
|
97
|
+
record: false,
|
|
98
|
+
userDataDir: null,
|
|
99
|
+
});
|
|
100
|
+
await browser.launch();
|
|
101
|
+
const wsEndpoint = browser.wsEndpoint();
|
|
102
|
+
|
|
103
|
+
if (!wsEndpoint) {
|
|
104
|
+
throw new Error('There was an error launching the browser');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const { port } = new URL(wsEndpoint);
|
|
108
|
+
const res = await fetch(`http://127.0.0.1:${port}/json/version`);
|
|
109
|
+
const meta = await res.json();
|
|
110
|
+
|
|
111
|
+
browser.close();
|
|
112
|
+
|
|
113
|
+
const { 'WebKit-Version': webkitVersion } = meta;
|
|
114
|
+
const debuggerVersion = webkitVersion.match(/\s\(@(\b[0-9a-f]{5,40}\b)/)[1];
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
...meta,
|
|
118
|
+
'Debugger-Version': debuggerVersion,
|
|
119
|
+
webSocketDebuggerUrl: this.config.getExternalWebSocketAddress(),
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
|
|
85
123
|
private generateSessionJson = async (
|
|
86
124
|
browser: BrowserInstance,
|
|
87
125
|
session: BrowserlessSession,
|
|
@@ -201,8 +239,8 @@ export class BrowserManager {
|
|
|
201
239
|
if (req.parsed.pathname.includes('/devtools/browser')) {
|
|
202
240
|
const sessions = Array.from(this.browsers);
|
|
203
241
|
const id = req.parsed.pathname.split('/').pop() as string;
|
|
204
|
-
const browser = sessions.find(
|
|
205
|
-
|
|
242
|
+
const browser = sessions.find(([b]) =>
|
|
243
|
+
b.wsEndpoint()?.includes(req.parsed.pathname),
|
|
206
244
|
);
|
|
207
245
|
|
|
208
246
|
if (browser) {
|
|
@@ -111,12 +111,11 @@ export class PlaywrightChromium extends EventEmitter {
|
|
|
111
111
|
return null;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
const serverURL = new URL(this.config.getExternalWebSocketAddress());
|
|
114
115
|
const wsURL = new URL(this.browserWSEndpoint);
|
|
115
|
-
const serverURL = new URL(this.config.getExternalAddress());
|
|
116
|
-
|
|
117
116
|
wsURL.hostname = serverURL.hostname;
|
|
118
117
|
wsURL.port = serverURL.port;
|
|
119
|
-
|
|
118
|
+
|
|
120
119
|
if (token) {
|
|
121
120
|
wsURL.searchParams.set('token', token);
|
|
122
121
|
}
|
|
@@ -104,12 +104,11 @@ export class PlaywrightFirefox extends EventEmitter {
|
|
|
104
104
|
return null;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
const serverURL = new URL(this.config.getExternalWebSocketAddress());
|
|
107
108
|
const wsURL = new URL(this.browserWSEndpoint);
|
|
108
|
-
const serverURL = new URL(this.config.getExternalAddress());
|
|
109
|
-
|
|
110
109
|
wsURL.hostname = serverURL.hostname;
|
|
111
110
|
wsURL.port = serverURL.port;
|
|
112
|
-
|
|
111
|
+
|
|
113
112
|
if (token) {
|
|
114
113
|
wsURL.searchParams.set('token', token);
|
|
115
114
|
}
|
|
@@ -104,12 +104,11 @@ export class PlaywrightWebkit extends EventEmitter {
|
|
|
104
104
|
return null;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
const serverURL = new URL(this.config.getExternalWebSocketAddress());
|
|
107
108
|
const wsURL = new URL(this.browserWSEndpoint);
|
|
108
|
-
const serverURL = new URL(this.config.getExternalAddress());
|
|
109
|
-
|
|
110
109
|
wsURL.hostname = serverURL.hostname;
|
|
111
110
|
wsURL.port = serverURL.port;
|
|
112
|
-
|
|
111
|
+
|
|
113
112
|
if (token) {
|
|
114
113
|
wsURL.searchParams.set('token', token);
|
|
115
114
|
}
|
package/src/config.ts
CHANGED
|
@@ -409,6 +409,23 @@ export class Config extends EventEmitter {
|
|
|
409
409
|
public getExternalAddress = (): string =>
|
|
410
410
|
this.external ?? this.getServerAddress();
|
|
411
411
|
|
|
412
|
+
/**
|
|
413
|
+
* Returns the the fully-qualified WebSocket URL for the
|
|
414
|
+
* external address that browserless might be
|
|
415
|
+
* running behind *or* the server address if
|
|
416
|
+
* no external URL is provided.
|
|
417
|
+
*
|
|
418
|
+
* @returns {string} The URL to reach the server
|
|
419
|
+
*/
|
|
420
|
+
public getExternalWebSocketAddress = (): string => {
|
|
421
|
+
const httpAddress = new URL(this.external ?? this.getServerAddress());
|
|
422
|
+
httpAddress.protocol = httpAddress.protocol.startsWith('https')
|
|
423
|
+
? 'wss:'
|
|
424
|
+
: 'ws:';
|
|
425
|
+
|
|
426
|
+
return httpAddress.href;
|
|
427
|
+
};
|
|
428
|
+
|
|
412
429
|
/**
|
|
413
430
|
* When CORS is enabled, returns relevant CORS headers
|
|
414
431
|
* to requests and for the OPTIONS call. Values can be
|
package/src/file-system.spec.ts
CHANGED