@rushstack/playwright-browser-tunnel 0.2.4 → 0.3.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.json +38 -0
- package/CHANGELOG.md +15 -1
- package/LICENSE +24 -0
- package/{lib → lib-dts}/tsdoc-metadata.json +1 -1
- package/lib-esm/HttpServer.js +70 -0
- package/lib-esm/HttpServer.js.map +1 -0
- package/lib-esm/LaunchOptionsValidator.js +156 -0
- package/lib-esm/LaunchOptionsValidator.js.map +1 -0
- package/lib-esm/PlaywrightBrowserTunnel.js +467 -0
- package/lib-esm/PlaywrightBrowserTunnel.js.map +1 -0
- package/{src/index.ts → lib-esm/index.js} +2 -18
- package/lib-esm/index.js.map +1 -0
- package/{src/tunneledBrowserConnection/constants.ts → lib-esm/tunneledBrowserConnection/ITunneledBrowser.js} +2 -3
- package/lib-esm/tunneledBrowserConnection/ITunneledBrowser.js.map +1 -0
- package/lib-esm/tunneledBrowserConnection/ITunneledBrowserConnection.js +4 -0
- package/lib-esm/tunneledBrowserConnection/ITunneledBrowserConnection.js.map +1 -0
- package/lib-esm/tunneledBrowserConnection/TunneledBrowser.js +36 -0
- package/lib-esm/tunneledBrowserConnection/TunneledBrowser.js.map +1 -0
- package/lib-esm/tunneledBrowserConnection/TunneledBrowserConnection.js +195 -0
- package/lib-esm/tunneledBrowserConnection/TunneledBrowserConnection.js.map +1 -0
- package/lib-esm/tunneledBrowserConnection/constants.js +5 -0
- package/lib-esm/tunneledBrowserConnection/constants.js.map +1 -0
- package/{src/tunneledBrowserConnection/index.ts → lib-esm/tunneledBrowserConnection/index.js} +1 -4
- package/lib-esm/tunneledBrowserConnection/index.js.map +1 -0
- package/lib-esm/utilities.js +96 -0
- package/lib-esm/utilities.js.map +1 -0
- package/package.json +30 -7
- package/.rush/temp/chunked-rush-logs/playwright-browser-tunnel._phase_build.chunks.jsonl +0 -8
- package/.rush/temp/operation/_phase_build/all.log +0 -8
- package/.rush/temp/operation/_phase_build/log-chunks.jsonl +0 -8
- package/.rush/temp/operation/_phase_build/state.json +0 -3
- package/.rush/temp/rushstack+playwright-browser-tunnel-_phase_build-517a2999ebe527b217bbfe2e265943b73bf3856b.tar.log +0 -62
- package/.rush/temp/shrinkwrap-deps.json +0 -104
- package/config/api-extractor.json +0 -19
- package/config/rig.json +0 -7
- package/eslint.config.js +0 -18
- package/playwright.config.ts +0 -45
- package/rush-logs/playwright-browser-tunnel._phase_build.cache.log +0 -3
- package/rush-logs/playwright-browser-tunnel._phase_build.log +0 -8
- package/src/HttpServer.ts +0 -87
- package/src/LaunchOptionsValidator.ts +0 -234
- package/src/PlaywrightBrowserTunnel.ts +0 -650
- package/src/tunneledBrowserConnection/ITunneledBrowser.ts +0 -20
- package/src/tunneledBrowserConnection/ITunneledBrowserConnection.ts +0 -37
- package/src/tunneledBrowserConnection/TunneledBrowser.ts +0 -52
- package/src/tunneledBrowserConnection/TunneledBrowserConnection.ts +0 -232
- package/src/utilities.ts +0 -136
- package/temp/build/lint/_eslint-5eVG3S6w.json +0 -50
- package/temp/build/lint/lint.sarif +0 -258
- package/temp/build/typescript/ts_l9Fw4VUO.json +0 -1
- package/temp/playwright-browser-tunnel.api.md +0 -120
- package/tests/demo.spec.ts +0 -10
- package/tests/testFixture.ts +0 -22
- package/tsconfig.json +0 -6
- /package/{lib → lib-commonjs}/HttpServer.js +0 -0
- /package/{lib → lib-commonjs}/HttpServer.js.map +0 -0
- /package/{lib → lib-commonjs}/LaunchOptionsValidator.js +0 -0
- /package/{lib → lib-commonjs}/LaunchOptionsValidator.js.map +0 -0
- /package/{lib → lib-commonjs}/PlaywrightBrowserTunnel.js +0 -0
- /package/{lib → lib-commonjs}/PlaywrightBrowserTunnel.js.map +0 -0
- /package/{lib → lib-commonjs}/index.js +0 -0
- /package/{lib → lib-commonjs}/index.js.map +0 -0
- /package/{lib → lib-commonjs}/tunneledBrowserConnection/ITunneledBrowser.js +0 -0
- /package/{lib → lib-commonjs}/tunneledBrowserConnection/ITunneledBrowser.js.map +0 -0
- /package/{lib → lib-commonjs}/tunneledBrowserConnection/ITunneledBrowserConnection.js +0 -0
- /package/{lib → lib-commonjs}/tunneledBrowserConnection/ITunneledBrowserConnection.js.map +0 -0
- /package/{lib → lib-commonjs}/tunneledBrowserConnection/TunneledBrowser.js +0 -0
- /package/{lib → lib-commonjs}/tunneledBrowserConnection/TunneledBrowser.js.map +0 -0
- /package/{lib → lib-commonjs}/tunneledBrowserConnection/TunneledBrowserConnection.js +0 -0
- /package/{lib → lib-commonjs}/tunneledBrowserConnection/TunneledBrowserConnection.js.map +0 -0
- /package/{lib → lib-commonjs}/tunneledBrowserConnection/constants.js +0 -0
- /package/{lib → lib-commonjs}/tunneledBrowserConnection/constants.js.map +0 -0
- /package/{lib → lib-commonjs}/tunneledBrowserConnection/index.js +0 -0
- /package/{lib → lib-commonjs}/tunneledBrowserConnection/index.js.map +0 -0
- /package/{lib → lib-commonjs}/utilities.js +0 -0
- /package/{lib → lib-commonjs}/utilities.js.map +0 -0
- /package/{lib → lib-dts}/HttpServer.d.ts +0 -0
- /package/{lib → lib-dts}/HttpServer.d.ts.map +0 -0
- /package/{lib → lib-dts}/LaunchOptionsValidator.d.ts +0 -0
- /package/{lib → lib-dts}/LaunchOptionsValidator.d.ts.map +0 -0
- /package/{lib → lib-dts}/PlaywrightBrowserTunnel.d.ts +0 -0
- /package/{lib → lib-dts}/PlaywrightBrowserTunnel.d.ts.map +0 -0
- /package/{lib → lib-dts}/index.d.ts +0 -0
- /package/{lib → lib-dts}/index.d.ts.map +0 -0
- /package/{lib → lib-dts}/tunneledBrowserConnection/ITunneledBrowser.d.ts +0 -0
- /package/{lib → lib-dts}/tunneledBrowserConnection/ITunneledBrowser.d.ts.map +0 -0
- /package/{lib → lib-dts}/tunneledBrowserConnection/ITunneledBrowserConnection.d.ts +0 -0
- /package/{lib → lib-dts}/tunneledBrowserConnection/ITunneledBrowserConnection.d.ts.map +0 -0
- /package/{lib → lib-dts}/tunneledBrowserConnection/TunneledBrowser.d.ts +0 -0
- /package/{lib → lib-dts}/tunneledBrowserConnection/TunneledBrowser.d.ts.map +0 -0
- /package/{lib → lib-dts}/tunneledBrowserConnection/TunneledBrowserConnection.d.ts +0 -0
- /package/{lib → lib-dts}/tunneledBrowserConnection/TunneledBrowserConnection.d.ts.map +0 -0
- /package/{lib → lib-dts}/tunneledBrowserConnection/constants.d.ts +0 -0
- /package/{lib → lib-dts}/tunneledBrowserConnection/constants.d.ts.map +0 -0
- /package/{lib → lib-dts}/tunneledBrowserConnection/index.d.ts +0 -0
- /package/{lib → lib-dts}/tunneledBrowserConnection/index.d.ts.map +0 -0
- /package/{lib → lib-dts}/utilities.d.ts +0 -0
- /package/{lib → lib-dts}/utilities.d.ts.map +0 -0
package/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/playwright-browser-tunnel",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.3.1",
|
|
6
|
+
"tag": "@rushstack/playwright-browser-tunnel_v0.3.1",
|
|
7
|
+
"date": "Thu, 19 Feb 2026 01:30:06 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "Filter files from publish and include missing LICENSE file."
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"version": "0.3.0",
|
|
18
|
+
"tag": "@rushstack/playwright-browser-tunnel_v0.3.0",
|
|
19
|
+
"date": "Thu, 19 Feb 2026 00:04:53 GMT",
|
|
20
|
+
"comments": {
|
|
21
|
+
"minor": [
|
|
22
|
+
{
|
|
23
|
+
"comment": "Normalize package layout. CommonJS is now under `lib-commonjs`, DTS is now under `lib-dts`, and ESM is now under `lib-esm`. Imports to `lib` still work as before, handled by the `\"exports\"` field in `package.json`."
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
"dependency": [
|
|
27
|
+
{
|
|
28
|
+
"comment": "Updating dependency \"@rushstack/node-core-library\" to `5.20.0`"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"comment": "Updating dependency \"@rushstack/terminal\" to `0.22.0`"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"comment": "Updating dependency \"@rushstack/ts-command-line\" to `5.3.0`"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"comment": "Updating dependency \"@rushstack/heft\" to `1.2.0`"
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
},
|
|
4
42
|
{
|
|
5
43
|
"version": "0.2.4",
|
|
6
44
|
"tag": "@rushstack/playwright-browser-tunnel_v0.2.4",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
# Change Log - @rushstack/playwright-browser-tunnel
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Thu, 19 Feb 2026 01:30:06 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 0.3.1
|
|
6
|
+
Thu, 19 Feb 2026 01:30:06 GMT
|
|
7
|
+
|
|
8
|
+
### Patches
|
|
9
|
+
|
|
10
|
+
- Filter files from publish and include missing LICENSE file.
|
|
11
|
+
|
|
12
|
+
## 0.3.0
|
|
13
|
+
Thu, 19 Feb 2026 00:04:53 GMT
|
|
14
|
+
|
|
15
|
+
### Minor changes
|
|
16
|
+
|
|
17
|
+
- Normalize package layout. CommonJS is now under `lib-commonjs`, DTS is now under `lib-dts`, and ESM is now under `lib-esm`. Imports to `lib` still work as before, handled by the `"exports"` field in `package.json`.
|
|
4
18
|
|
|
5
19
|
## 0.2.4
|
|
6
20
|
Wed, 11 Feb 2026 23:14:09 GMT
|
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
@rushstack/playwright-browser-tunnel
|
|
2
|
+
|
|
3
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
|
|
5
|
+
MIT License
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
8
|
+
a copy of this software and associated documentation files (the
|
|
9
|
+
"Software"), to deal in the Software without restriction, including
|
|
10
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
11
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
12
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
13
|
+
the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be
|
|
16
|
+
included in all copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
19
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
20
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
21
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
22
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
23
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
24
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
import http from 'node:http';
|
|
4
|
+
import { URL } from 'node:url';
|
|
5
|
+
import { WebSocketServer } from 'ws';
|
|
6
|
+
const LOCALHOST = 'localhost';
|
|
7
|
+
/**
|
|
8
|
+
* Formats an address info object into a WebSocket-compatible address string.
|
|
9
|
+
* IPv6 addresses are formatted with brackets: [address]:port
|
|
10
|
+
* IPv4 addresses are formatted as: address:port
|
|
11
|
+
*/
|
|
12
|
+
function formatAddress(addressInfo) {
|
|
13
|
+
return addressInfo.family === 'IPv6'
|
|
14
|
+
? `[${addressInfo.address}]:${addressInfo.port}`
|
|
15
|
+
: `${addressInfo.address}:${addressInfo.port}`;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* This HttpServer is used for the localProxyWs WebSocketServer.
|
|
19
|
+
* The purpose is to parse the query params and path for the websocket url to get the
|
|
20
|
+
* browserName and launchOptions.
|
|
21
|
+
*/
|
|
22
|
+
export class HttpServer {
|
|
23
|
+
constructor(logger) {
|
|
24
|
+
this._logger = logger;
|
|
25
|
+
// We'll create an HTTP server and attach a WebSocketServer in noServer mode so we can
|
|
26
|
+
// manually parse the URL and extract query parameters before upgrading.
|
|
27
|
+
this._server = http.createServer();
|
|
28
|
+
this._wsServer = new WebSocketServer({ noServer: true });
|
|
29
|
+
this._server.on('upgrade', (request, socket, head) => {
|
|
30
|
+
// Accept all upgrades on the root path. We parse query string for browserName + launchOptions.
|
|
31
|
+
this._wsServer.handleUpgrade(request, socket, head, (ws) => {
|
|
32
|
+
this._wsServer.emit('connection', ws, request);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async listenAsync() {
|
|
37
|
+
return await new Promise((resolve) => {
|
|
38
|
+
// Bind to 'localhost' which resolves to IPv4 (127.0.0.1) or IPv6 (::1)
|
|
39
|
+
// depending on system configuration and DNS resolution
|
|
40
|
+
this._server.listen(0, LOCALHOST, () => {
|
|
41
|
+
const addressInfo = this._server.address();
|
|
42
|
+
if (!addressInfo) {
|
|
43
|
+
throw new Error('Server address is null - server may not be bound properly');
|
|
44
|
+
}
|
|
45
|
+
if (typeof addressInfo === 'string') {
|
|
46
|
+
throw new Error(`Server address is a pipe/socket path (${addressInfo}), expected an IP address`);
|
|
47
|
+
}
|
|
48
|
+
const formattedAddress = formatAddress(addressInfo);
|
|
49
|
+
this._listeningAddress = formattedAddress;
|
|
50
|
+
// This MUST be printed to terminal so VS Code can auto-port forward
|
|
51
|
+
this._logger.writeLine(`Local proxy HttpServer listening at ws://${formattedAddress}`);
|
|
52
|
+
resolve(new URL(`ws://${formattedAddress}`));
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
get endpoint() {
|
|
57
|
+
if (this._listeningAddress === undefined) {
|
|
58
|
+
throw new Error('HttpServer not listening yet');
|
|
59
|
+
}
|
|
60
|
+
return `ws://${this._listeningAddress}`;
|
|
61
|
+
}
|
|
62
|
+
get wsServer() {
|
|
63
|
+
return this._wsServer;
|
|
64
|
+
}
|
|
65
|
+
[Symbol.dispose]() {
|
|
66
|
+
this._wsServer.close();
|
|
67
|
+
this._server.close();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=HttpServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpServer.js","sourceRoot":"","sources":["../src/HttpServer.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAE3D,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,EAAE,eAAe,EAAkB,MAAM,IAAI,CAAC;AAIrD,MAAM,SAAS,GAAW,WAAW,CAAC;AAEtC;;;;GAIG;AACH,SAAS,aAAa,CAAC,WAAwB;IAC7C,OAAO,WAAW,CAAC,MAAM,KAAK,MAAM;QAClC,CAAC,CAAC,IAAI,WAAW,CAAC,OAAO,KAAK,WAAW,CAAC,IAAI,EAAE;QAChD,CAAC,CAAC,GAAG,WAAW,CAAC,OAAO,IAAI,WAAW,CAAC,IAAI,EAAE,CAAC;AACnD,CAAC;AAED;;;;GAIG;AACH,MAAM,OAAO,UAAU;IAMrB,YAAmB,MAAiB;QAClC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,sFAAsF;QACtF,wEAAwE;QACxE,IAAI,CAAC,OA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,gBAAgB,EAAE,CAAC,CAAC,CAAC;YAC/C,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAW,QAAQ;QACjB,IAAI,IAAI,CAAC,iBAAiB,KAAK,SAAS,EAAE,CAAC;YACzC,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAClD,CAAC;QACD,OAAO,QAAQ,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC1C,CAAC;IAED,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAEM,CAAC,MAAM,CAAC,OAAO,CAAC;QACrB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACvB,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport http from 'node:http';\nimport type { AddressInfo } from 'node:net';\nimport { URL } from 'node:url';\n\nimport { WebSocketServer, type WebSocket } from 'ws';\n\nimport type { ITerminal } from '@rushstack/terminal';\n\nconst LOCALHOST: string = 'localhost';\n\n/**\n * Formats an address info object into a WebSocket-compatible address string.\n * IPv6 addresses are formatted with brackets: [address]:port\n * IPv4 addresses are formatted as: address:port\n */\nfunction formatAddress(addressInfo: AddressInfo): string {\n return addressInfo.family === 'IPv6'\n ? `[${addressInfo.address}]:${addressInfo.port}`\n : `${addressInfo.address}:${addressInfo.port}`;\n}\n\n/**\n * This HttpServer is used for the localProxyWs WebSocketServer.\n * The purpose is to parse the query params and path for the websocket url to get the\n * browserName and launchOptions.\n */\nexport class HttpServer {\n private readonly _server: http.Server;\n private readonly _wsServer: WebSocketServer; // local proxy websocket server accepting browser clients\n private _listeningAddress: string | undefined;\n private _logger: ITerminal;\n\n public constructor(logger: ITerminal) {\n this._logger = logger;\n // We'll create an HTTP server and attach a WebSocketServer in noServer mode so we can\n // manually parse the URL and extract query parameters before upgrading.\n this._server = http.createServer();\n this._wsServer = new WebSocketServer({ noServer: true });\n\n this._server.on('upgrade', (request, socket, head) => {\n // Accept all upgrades on the root path. We parse query string for browserName + launchOptions.\n this._wsServer.handleUpgrade(request, socket, head, (ws: WebSocket) => {\n this._wsServer.emit('connection', ws, request);\n });\n });\n }\n\n public async listenAsync(): Promise<URL> {\n return await new Promise((resolve) => {\n // Bind to 'localhost' which resolves to IPv4 (127.0.0.1) or IPv6 (::1)\n // depending on system configuration and DNS resolution\n this._server.listen(0, LOCALHOST, () => {\n const addressInfo: AddressInfo | string | null = this._server.address();\n if (!addressInfo) {\n throw new Error('Server address is null - server may not be bound properly');\n }\n if (typeof addressInfo === 'string') {\n throw new Error(`Server address is a pipe/socket path (${addressInfo}), expected an IP address`);\n }\n const formattedAddress: string = formatAddress(addressInfo);\n this._listeningAddress = formattedAddress;\n // This MUST be printed to terminal so VS Code can auto-port forward\n this._logger.writeLine(`Local proxy HttpServer listening at ws://${formattedAddress}`);\n resolve(new URL(`ws://${formattedAddress}`));\n });\n });\n }\n\n public get endpoint(): string {\n if (this._listeningAddress === undefined) {\n throw new Error('HttpServer not listening yet');\n }\n return `ws://${this._listeningAddress}`;\n }\n\n public get wsServer(): WebSocketServer {\n return this._wsServer;\n }\n\n public [Symbol.dispose](): void {\n this._wsServer.close();\n this._server.close();\n }\n}\n"]}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
2
|
+
// See LICENSE in the project root for license information.
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { FileSystem } from '@rushstack/node-core-library';
|
|
6
|
+
/**
|
|
7
|
+
* The filename used to store the launch options allowlist.
|
|
8
|
+
* Stored in the user's home directory/.playwright-browser-tunnel folder.
|
|
9
|
+
* @beta
|
|
10
|
+
*/
|
|
11
|
+
export const LAUNCH_OPTIONS_ALLOWLIST_FILENAME = '.playwright-launch-options-allowlist.json';
|
|
12
|
+
/**
|
|
13
|
+
* Validates Playwright launch options against security allowlists.
|
|
14
|
+
* Provides utilities for managing client-side allowlist configuration.
|
|
15
|
+
* @beta
|
|
16
|
+
*/
|
|
17
|
+
export class LaunchOptionsValidator {
|
|
18
|
+
/**
|
|
19
|
+
* Gets the path to the allowlist file in the user's local preferences folder.
|
|
20
|
+
* This follows the pattern of playwright-browser-installed.txt but stores in user's home directory.
|
|
21
|
+
*/
|
|
22
|
+
static getAllowlistFilePath() {
|
|
23
|
+
// Store in user's home directory under .playwright-browser-tunnel
|
|
24
|
+
const homeDir = os.homedir();
|
|
25
|
+
const configDir = path.join(homeDir, '.playwright-browser-tunnel');
|
|
26
|
+
return path.join(configDir, LAUNCH_OPTIONS_ALLOWLIST_FILENAME);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Reads the allowlist from the user's local file system.
|
|
30
|
+
* Returns an empty allowlist if the file doesn't exist or is invalid.
|
|
31
|
+
*/
|
|
32
|
+
static async readAllowlistAsync() {
|
|
33
|
+
const allowlistPath = this.getAllowlistFilePath();
|
|
34
|
+
try {
|
|
35
|
+
if (!FileSystem.exists(allowlistPath)) {
|
|
36
|
+
return {
|
|
37
|
+
allowedOptions: [],
|
|
38
|
+
version: this._allowlistVersion
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const content = await FileSystem.readFileAsync(allowlistPath);
|
|
42
|
+
const parsed = JSON.parse(content);
|
|
43
|
+
if (typeof parsed === 'object' &&
|
|
44
|
+
parsed !== null &&
|
|
45
|
+
'allowedOptions' in parsed &&
|
|
46
|
+
Array.isArray(parsed.allowedOptions) &&
|
|
47
|
+
'version' in parsed &&
|
|
48
|
+
typeof parsed.version === 'number') {
|
|
49
|
+
return parsed;
|
|
50
|
+
}
|
|
51
|
+
// Invalid format, return empty allowlist
|
|
52
|
+
return {
|
|
53
|
+
allowedOptions: [],
|
|
54
|
+
version: this._allowlistVersion
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
// If we can't read the file, return empty allowlist
|
|
59
|
+
return {
|
|
60
|
+
allowedOptions: [],
|
|
61
|
+
version: this._allowlistVersion
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Writes the allowlist to the user's local file system.
|
|
67
|
+
*/
|
|
68
|
+
static async writeAllowlistAsync(allowlist) {
|
|
69
|
+
const allowlistPath = this.getAllowlistFilePath();
|
|
70
|
+
const configDir = path.dirname(allowlistPath);
|
|
71
|
+
// Ensure the config directory exists
|
|
72
|
+
await FileSystem.ensureFolderAsync(configDir);
|
|
73
|
+
const content = JSON.stringify(allowlist, null, 2);
|
|
74
|
+
await FileSystem.writeFileAsync(allowlistPath, content, { ensureFolderExists: true });
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Validates launch options against the security allowlist.
|
|
78
|
+
* All launch options are denied by default unless explicitly allowed by the user.
|
|
79
|
+
*
|
|
80
|
+
* @param launchOptions - The launch options to validate
|
|
81
|
+
* @param terminal - Optional terminal for logging warnings
|
|
82
|
+
* @returns Validation result with filtered options and warnings
|
|
83
|
+
*/
|
|
84
|
+
static async validateLaunchOptionsAsync(launchOptions, terminal) {
|
|
85
|
+
const allowlist = await this.readAllowlistAsync();
|
|
86
|
+
const allowedOptionsSet = new Set(allowlist.allowedOptions);
|
|
87
|
+
const deniedOptions = [];
|
|
88
|
+
const warnings = [];
|
|
89
|
+
const filteredOptions = {};
|
|
90
|
+
// Check each provided launch option - deny all unless explicitly allowed
|
|
91
|
+
for (const key of Object.keys(launchOptions)) {
|
|
92
|
+
if (allowedOptionsSet.has(key)) {
|
|
93
|
+
// Option is in the user's allowlist - permit it
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
95
|
+
filteredOptions[key] = launchOptions[key];
|
|
96
|
+
if (terminal) {
|
|
97
|
+
terminal.writeWarningLine(`Launch option '${key}' is allowed by user allowlist. ` +
|
|
98
|
+
`Value: ${JSON.stringify(launchOptions[key])}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
// Option is not in allowlist - deny it
|
|
103
|
+
deniedOptions.push(key);
|
|
104
|
+
const warning = `Launch option '${key}' was denied (not in allowlist). ` +
|
|
105
|
+
`To allow this option, add it to your local allowlist at: ${this.getAllowlistFilePath()}`;
|
|
106
|
+
warnings.push(warning);
|
|
107
|
+
if (terminal) {
|
|
108
|
+
terminal.writeWarningLine(warning);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
isValid: deniedOptions.length === 0,
|
|
114
|
+
deniedOptions,
|
|
115
|
+
filteredOptions,
|
|
116
|
+
warnings
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Adds an option to the allowlist.
|
|
121
|
+
*/
|
|
122
|
+
static async addToAllowlistAsync(option) {
|
|
123
|
+
const allowlist = await this.readAllowlistAsync();
|
|
124
|
+
if (!allowlist.allowedOptions.includes(option)) {
|
|
125
|
+
allowlist.allowedOptions.push(option);
|
|
126
|
+
await this.writeAllowlistAsync(allowlist);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Removes an option from the allowlist.
|
|
131
|
+
*/
|
|
132
|
+
static async removeFromAllowlistAsync(option) {
|
|
133
|
+
const allowlist = await this.readAllowlistAsync();
|
|
134
|
+
allowlist.allowedOptions = allowlist.allowedOptions.filter((opt) => opt !== option);
|
|
135
|
+
await this.writeAllowlistAsync(allowlist);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Clears the entire allowlist.
|
|
139
|
+
*/
|
|
140
|
+
static async clearAllowlistAsync() {
|
|
141
|
+
await this.writeAllowlistAsync({
|
|
142
|
+
allowedOptions: [],
|
|
143
|
+
version: this._allowlistVersion
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Gets a human-readable description of the allowlist security model.
|
|
148
|
+
*/
|
|
149
|
+
static getAllowlistDescription() {
|
|
150
|
+
return (`All launch options are denied by default for security.\n` +
|
|
151
|
+
`Only options explicitly added to your allowlist will be permitted.\n\n` +
|
|
152
|
+
`Allowlist location: ${this.getAllowlistFilePath()}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
LaunchOptionsValidator._allowlistVersion = 1;
|
|
156
|
+
//# sourceMappingURL=LaunchOptionsValidator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LaunchOptionsValidator.js","sourceRoot":"","sources":["../src/LaunchOptionsValidator.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAE3D,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAI7B,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAG1D;;;;GAIG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAW,2CAA2C,CAAC;AA6CrG;;;;GAIG;AACH,MAAM,OAAO,sBAAsB;IAGjC;;;OAGG;IACI,MAAM,CAAC,oBAAoB;QAChC,kEAAkE;QAClE,MAAM,OAAO,GAAW,EAAE,CAAC,OAAO,EAAE,CAAC;QACrC,MAAM,SAAS,GAAW,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,4BAA4B,CAAC,CAAC;QAC3E,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,iCAAiC,CAAC,CAAC;IACjE,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,KAAK,CAAC,kBAAkB;QACpC,MAAM,aAAa,GAAW,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAE1D,IAAI,CAAC;YACH,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;gBACtC,OAAO;oBACL,cAAc,EAAE,EAAE;oBAClB,OAAO,EAA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G;IACI,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,MAA2B;QACjE,MAAM,SAAS,GAA4B,MAAM,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAE3E,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YAC/C,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACtC,MAAM,IAAI,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,MAA2B;QACtE,MAAM,SAAS,GAA4B,MAAM,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC3E,SAAS,CAAC,cAAc,GAAG,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,MAAM,CAAC,CAAC;QACpF,MAAM,IAAI,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;IAC5C,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,KAAK,CAAC,mBAAmB;QACrC,MAAM,IAAI,CAAC,mBAAmB,CAAC;YAC7B,cAAc,EAAE,EAAE;YAClB,OAAO,EAAE,IAAI,CAAC,iBAAiB;SAChC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,uBAAuB;QACnC,OAAO,CACL,0DAA0D;YAC1D,wEAAwE;YACxE,uBAAuB,IAAI,CAAC,oBAAoB,EAAE,EAAE,CACrD,CAAC;IACJ,CAAC;;AArKuB,wCAAiB,GAAW,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport os from 'node:os';\nimport path from 'node:path';\n\nimport type { LaunchOptions } from 'playwright-core';\n\nimport { FileSystem } from '@rushstack/node-core-library';\nimport type { ITerminal } from '@rushstack/terminal';\n\n/**\n * The filename used to store the launch options allowlist.\n * Stored in the user's home directory/.playwright-browser-tunnel folder.\n * @beta\n */\nexport const LAUNCH_OPTIONS_ALLOWLIST_FILENAME: string = '.playwright-launch-options-allowlist.json';\n\n/**\n * Interface for the allowlist configuration stored in the user's local file system.\n * @beta\n */\nexport interface ILaunchOptionsAllowlist {\n /**\n * Set of launch option keys that the user has explicitly allowed.\n * These bypass the default security restrictions.\n */\n allowedOptions: string[];\n\n /**\n * Version of the allowlist format, for future compatibility.\n */\n version: number;\n}\n\n/**\n * Result of validating launch options against the allowlist.\n * @beta\n */\nexport interface ILaunchOptionsValidationResult {\n /**\n * Whether the launch options are valid and allowed.\n */\n isValid: boolean;\n\n /**\n * Launch options that were denied due to security restrictions.\n */\n deniedOptions: Array<keyof LaunchOptions>;\n\n /**\n * Filtered launch options with denied properties removed.\n */\n filteredOptions: LaunchOptions;\n\n /**\n * Warning messages about denied options.\n */\n warnings: string[];\n}\n\n/**\n * Validates Playwright launch options against security allowlists.\n * Provides utilities for managing client-side allowlist configuration.\n * @beta\n */\nexport class LaunchOptionsValidator {\n private static readonly _allowlistVersion: number = 1;\n\n /**\n * Gets the path to the allowlist file in the user's local preferences folder.\n * This follows the pattern of playwright-browser-installed.txt but stores in user's home directory.\n */\n public static getAllowlistFilePath(): string {\n // Store in user's home directory under .playwright-browser-tunnel\n const homeDir: string = os.homedir();\n const configDir: string = path.join(homeDir, '.playwright-browser-tunnel');\n return path.join(configDir, LAUNCH_OPTIONS_ALLOWLIST_FILENAME);\n }\n\n /**\n * Reads the allowlist from the user's local file system.\n * Returns an empty allowlist if the file doesn't exist or is invalid.\n */\n public static async readAllowlistAsync(): Promise<ILaunchOptionsAllowlist> {\n const allowlistPath: string = this.getAllowlistFilePath();\n\n try {\n if (!FileSystem.exists(allowlistPath)) {\n return {\n allowedOptions: [],\n version: this._allowlistVersion\n };\n }\n\n const content: string = await FileSystem.readFileAsync(allowlistPath);\n const parsed: unknown = JSON.parse(content);\n\n if (\n typeof parsed === 'object' &&\n parsed !== null &&\n 'allowedOptions' in parsed &&\n Array.isArray(parsed.allowedOptions) &&\n 'version' in parsed &&\n typeof parsed.version === 'number'\n ) {\n return parsed as ILaunchOptionsAllowlist;\n }\n\n // Invalid format, return empty allowlist\n return {\n allowedOptions: [],\n version: this._allowlistVersion\n };\n } catch (error) {\n // If we can't read the file, return empty allowlist\n return {\n allowedOptions: [],\n version: this._allowlistVersion\n };\n }\n }\n\n /**\n * Writes the allowlist to the user's local file system.\n */\n public static async writeAllowlistAsync(allowlist: ILaunchOptionsAllowlist): Promise<void> {\n const allowlistPath: string = this.getAllowlistFilePath();\n const configDir: string = path.dirname(allowlistPath);\n\n // Ensure the config directory exists\n await FileSystem.ensureFolderAsync(configDir);\n\n const content: string = JSON.stringify(allowlist, null, 2);\n await FileSystem.writeFileAsync(allowlistPath, content, { ensureFolderExists: true });\n }\n\n /**\n * Validates launch options against the security allowlist.\n * All launch options are denied by default unless explicitly allowed by the user.\n *\n * @param launchOptions - The launch options to validate\n * @param terminal - Optional terminal for logging warnings\n * @returns Validation result with filtered options and warnings\n */\n public static async validateLaunchOptionsAsync(\n launchOptions: LaunchOptions,\n terminal?: ITerminal\n ): Promise<ILaunchOptionsValidationResult> {\n const allowlist: ILaunchOptionsAllowlist = await this.readAllowlistAsync();\n const allowedOptionsSet: Set<string> = new Set(allowlist.allowedOptions);\n\n const deniedOptions: Array<keyof LaunchOptions> = [];\n const warnings: string[] = [];\n const filteredOptions: LaunchOptions = {};\n\n // Check each provided launch option - deny all unless explicitly allowed\n for (const key of Object.keys(launchOptions) as Array<keyof LaunchOptions>) {\n if (allowedOptionsSet.has(key)) {\n // Option is in the user's allowlist - permit it\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (filteredOptions as any)[key] = launchOptions[key];\n\n if (terminal) {\n terminal.writeWarningLine(\n `Launch option '${key}' is allowed by user allowlist. ` +\n `Value: ${JSON.stringify(launchOptions[key])}`\n );\n }\n } else {\n // Option is not in allowlist - deny it\n deniedOptions.push(key);\n\n const warning: string =\n `Launch option '${key}' was denied (not in allowlist). ` +\n `To allow this option, add it to your local allowlist at: ${this.getAllowlistFilePath()}`;\n warnings.push(warning);\n\n if (terminal) {\n terminal.writeWarningLine(warning);\n }\n }\n }\n\n return {\n isValid: deniedOptions.length === 0,\n deniedOptions,\n filteredOptions,\n warnings\n };\n }\n\n /**\n * Adds an option to the allowlist.\n */\n public static async addToAllowlistAsync(option: keyof LaunchOptions): Promise<void> {\n const allowlist: ILaunchOptionsAllowlist = await this.readAllowlistAsync();\n\n if (!allowlist.allowedOptions.includes(option)) {\n allowlist.allowedOptions.push(option);\n await this.writeAllowlistAsync(allowlist);\n }\n }\n\n /**\n * Removes an option from the allowlist.\n */\n public static async removeFromAllowlistAsync(option: keyof LaunchOptions): Promise<void> {\n const allowlist: ILaunchOptionsAllowlist = await this.readAllowlistAsync();\n allowlist.allowedOptions = allowlist.allowedOptions.filter((opt) => opt !== option);\n await this.writeAllowlistAsync(allowlist);\n }\n\n /**\n * Clears the entire allowlist.\n */\n public static async clearAllowlistAsync(): Promise<void> {\n await this.writeAllowlistAsync({\n allowedOptions: [],\n version: this._allowlistVersion\n });\n }\n\n /**\n * Gets a human-readable description of the allowlist security model.\n */\n public static getAllowlistDescription(): string {\n return (\n `All launch options are denied by default for security.\\n` +\n `Only options explicitly added to your allowlist will be permitted.\\n\\n` +\n `Allowlist location: ${this.getAllowlistFilePath()}`\n );\n }\n}\n"]}
|