@rushstack/playwright-browser-tunnel 0.3.0 → 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.
Files changed (35) hide show
  1. package/CHANGELOG.json +12 -0
  2. package/CHANGELOG.md +8 -1
  3. package/LICENSE +24 -0
  4. package/lib-dts/tsdoc-metadata.json +1 -1
  5. package/package.json +3 -3
  6. package/.rush/temp/chunked-rush-logs/playwright-browser-tunnel._phase_build.chunks.jsonl +0 -8
  7. package/.rush/temp/operation/_phase_build/all.log +0 -8
  8. package/.rush/temp/operation/_phase_build/log-chunks.jsonl +0 -8
  9. package/.rush/temp/operation/_phase_build/state.json +0 -3
  10. package/.rush/temp/rushstack+playwright-browser-tunnel-_phase_build-7739ed2cac57efca3ad3fa4de550f08e1f482854.tar.log +0 -84
  11. package/.rush/temp/shrinkwrap-deps.json +0 -104
  12. package/config/api-extractor.json +0 -19
  13. package/config/rig.json +0 -7
  14. package/eslint.config.js +0 -18
  15. package/playwright.config.ts +0 -45
  16. package/rush-logs/playwright-browser-tunnel._phase_build.cache.log +0 -3
  17. package/rush-logs/playwright-browser-tunnel._phase_build.log +0 -8
  18. package/src/HttpServer.ts +0 -87
  19. package/src/LaunchOptionsValidator.ts +0 -234
  20. package/src/PlaywrightBrowserTunnel.ts +0 -650
  21. package/src/index.ts +0 -38
  22. package/src/tunneledBrowserConnection/ITunneledBrowser.ts +0 -20
  23. package/src/tunneledBrowserConnection/ITunneledBrowserConnection.ts +0 -37
  24. package/src/tunneledBrowserConnection/TunneledBrowser.ts +0 -52
  25. package/src/tunneledBrowserConnection/TunneledBrowserConnection.ts +0 -232
  26. package/src/tunneledBrowserConnection/constants.ts +0 -5
  27. package/src/tunneledBrowserConnection/index.ts +0 -8
  28. package/src/utilities.ts +0 -136
  29. package/temp/build/lint/_eslint-5eVG3S6w.json +0 -50
  30. package/temp/build/lint/lint.sarif +0 -258
  31. package/temp/build/typescript/ts_lnwgbP5O.json +0 -1
  32. package/temp/playwright-browser-tunnel.api.md +0 -120
  33. package/tests/demo.spec.ts +0 -10
  34. package/tests/testFixture.ts +0 -22
  35. package/tsconfig.json +0 -6
@@ -1,234 +0,0 @@
1
- // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2
- // See LICENSE in the project root for license information.
3
-
4
- import os from 'node:os';
5
- import path from 'node:path';
6
-
7
- import type { LaunchOptions } from 'playwright-core';
8
-
9
- import { FileSystem } from '@rushstack/node-core-library';
10
- import type { ITerminal } from '@rushstack/terminal';
11
-
12
- /**
13
- * The filename used to store the launch options allowlist.
14
- * Stored in the user's home directory/.playwright-browser-tunnel folder.
15
- * @beta
16
- */
17
- export const LAUNCH_OPTIONS_ALLOWLIST_FILENAME: string = '.playwright-launch-options-allowlist.json';
18
-
19
- /**
20
- * Interface for the allowlist configuration stored in the user's local file system.
21
- * @beta
22
- */
23
- export interface ILaunchOptionsAllowlist {
24
- /**
25
- * Set of launch option keys that the user has explicitly allowed.
26
- * These bypass the default security restrictions.
27
- */
28
- allowedOptions: string[];
29
-
30
- /**
31
- * Version of the allowlist format, for future compatibility.
32
- */
33
- version: number;
34
- }
35
-
36
- /**
37
- * Result of validating launch options against the allowlist.
38
- * @beta
39
- */
40
- export interface ILaunchOptionsValidationResult {
41
- /**
42
- * Whether the launch options are valid and allowed.
43
- */
44
- isValid: boolean;
45
-
46
- /**
47
- * Launch options that were denied due to security restrictions.
48
- */
49
- deniedOptions: Array<keyof LaunchOptions>;
50
-
51
- /**
52
- * Filtered launch options with denied properties removed.
53
- */
54
- filteredOptions: LaunchOptions;
55
-
56
- /**
57
- * Warning messages about denied options.
58
- */
59
- warnings: string[];
60
- }
61
-
62
- /**
63
- * Validates Playwright launch options against security allowlists.
64
- * Provides utilities for managing client-side allowlist configuration.
65
- * @beta
66
- */
67
- export class LaunchOptionsValidator {
68
- private static readonly _allowlistVersion: number = 1;
69
-
70
- /**
71
- * Gets the path to the allowlist file in the user's local preferences folder.
72
- * This follows the pattern of playwright-browser-installed.txt but stores in user's home directory.
73
- */
74
- public static getAllowlistFilePath(): string {
75
- // Store in user's home directory under .playwright-browser-tunnel
76
- const homeDir: string = os.homedir();
77
- const configDir: string = path.join(homeDir, '.playwright-browser-tunnel');
78
- return path.join(configDir, LAUNCH_OPTIONS_ALLOWLIST_FILENAME);
79
- }
80
-
81
- /**
82
- * Reads the allowlist from the user's local file system.
83
- * Returns an empty allowlist if the file doesn't exist or is invalid.
84
- */
85
- public static async readAllowlistAsync(): Promise<ILaunchOptionsAllowlist> {
86
- const allowlistPath: string = this.getAllowlistFilePath();
87
-
88
- try {
89
- if (!FileSystem.exists(allowlistPath)) {
90
- return {
91
- allowedOptions: [],
92
- version: this._allowlistVersion
93
- };
94
- }
95
-
96
- const content: string = await FileSystem.readFileAsync(allowlistPath);
97
- const parsed: unknown = JSON.parse(content);
98
-
99
- if (
100
- typeof parsed === 'object' &&
101
- parsed !== null &&
102
- 'allowedOptions' in parsed &&
103
- Array.isArray(parsed.allowedOptions) &&
104
- 'version' in parsed &&
105
- typeof parsed.version === 'number'
106
- ) {
107
- return parsed as ILaunchOptionsAllowlist;
108
- }
109
-
110
- // Invalid format, return empty allowlist
111
- return {
112
- allowedOptions: [],
113
- version: this._allowlistVersion
114
- };
115
- } catch (error) {
116
- // If we can't read the file, return empty allowlist
117
- return {
118
- allowedOptions: [],
119
- version: this._allowlistVersion
120
- };
121
- }
122
- }
123
-
124
- /**
125
- * Writes the allowlist to the user's local file system.
126
- */
127
- public static async writeAllowlistAsync(allowlist: ILaunchOptionsAllowlist): Promise<void> {
128
- const allowlistPath: string = this.getAllowlistFilePath();
129
- const configDir: string = path.dirname(allowlistPath);
130
-
131
- // Ensure the config directory exists
132
- await FileSystem.ensureFolderAsync(configDir);
133
-
134
- const content: string = JSON.stringify(allowlist, null, 2);
135
- await FileSystem.writeFileAsync(allowlistPath, content, { ensureFolderExists: true });
136
- }
137
-
138
- /**
139
- * Validates launch options against the security allowlist.
140
- * All launch options are denied by default unless explicitly allowed by the user.
141
- *
142
- * @param launchOptions - The launch options to validate
143
- * @param terminal - Optional terminal for logging warnings
144
- * @returns Validation result with filtered options and warnings
145
- */
146
- public static async validateLaunchOptionsAsync(
147
- launchOptions: LaunchOptions,
148
- terminal?: ITerminal
149
- ): Promise<ILaunchOptionsValidationResult> {
150
- const allowlist: ILaunchOptionsAllowlist = await this.readAllowlistAsync();
151
- const allowedOptionsSet: Set<string> = new Set(allowlist.allowedOptions);
152
-
153
- const deniedOptions: Array<keyof LaunchOptions> = [];
154
- const warnings: string[] = [];
155
- const filteredOptions: LaunchOptions = {};
156
-
157
- // Check each provided launch option - deny all unless explicitly allowed
158
- for (const key of Object.keys(launchOptions) as Array<keyof LaunchOptions>) {
159
- if (allowedOptionsSet.has(key)) {
160
- // Option is in the user's allowlist - permit it
161
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
162
- (filteredOptions as any)[key] = launchOptions[key];
163
-
164
- if (terminal) {
165
- terminal.writeWarningLine(
166
- `Launch option '${key}' is allowed by user allowlist. ` +
167
- `Value: ${JSON.stringify(launchOptions[key])}`
168
- );
169
- }
170
- } else {
171
- // Option is not in allowlist - deny it
172
- deniedOptions.push(key);
173
-
174
- const warning: string =
175
- `Launch option '${key}' was denied (not in allowlist). ` +
176
- `To allow this option, add it to your local allowlist at: ${this.getAllowlistFilePath()}`;
177
- warnings.push(warning);
178
-
179
- if (terminal) {
180
- terminal.writeWarningLine(warning);
181
- }
182
- }
183
- }
184
-
185
- return {
186
- isValid: deniedOptions.length === 0,
187
- deniedOptions,
188
- filteredOptions,
189
- warnings
190
- };
191
- }
192
-
193
- /**
194
- * Adds an option to the allowlist.
195
- */
196
- public static async addToAllowlistAsync(option: keyof LaunchOptions): Promise<void> {
197
- const allowlist: ILaunchOptionsAllowlist = await this.readAllowlistAsync();
198
-
199
- if (!allowlist.allowedOptions.includes(option)) {
200
- allowlist.allowedOptions.push(option);
201
- await this.writeAllowlistAsync(allowlist);
202
- }
203
- }
204
-
205
- /**
206
- * Removes an option from the allowlist.
207
- */
208
- public static async removeFromAllowlistAsync(option: keyof LaunchOptions): Promise<void> {
209
- const allowlist: ILaunchOptionsAllowlist = await this.readAllowlistAsync();
210
- allowlist.allowedOptions = allowlist.allowedOptions.filter((opt) => opt !== option);
211
- await this.writeAllowlistAsync(allowlist);
212
- }
213
-
214
- /**
215
- * Clears the entire allowlist.
216
- */
217
- public static async clearAllowlistAsync(): Promise<void> {
218
- await this.writeAllowlistAsync({
219
- allowedOptions: [],
220
- version: this._allowlistVersion
221
- });
222
- }
223
-
224
- /**
225
- * Gets a human-readable description of the allowlist security model.
226
- */
227
- public static getAllowlistDescription(): string {
228
- return (
229
- `All launch options are denied by default for security.\n` +
230
- `Only options explicitly added to your allowlist will be permitted.\n\n` +
231
- `Allowlist location: ${this.getAllowlistFilePath()}`
232
- );
233
- }
234
- }