@rushstack/playwright-browser-tunnel 0.3.0 → 0.3.2
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-dts/tsdoc-metadata.json +1 -1
- package/package.json +7 -5
- 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-7739ed2cac57efca3ad3fa4de550f08e1f482854.tar.log +0 -84
- 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/index.ts +0 -38
- 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/tunneledBrowserConnection/constants.ts +0 -5
- package/src/tunneledBrowserConnection/index.ts +0 -8
- 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_lnwgbP5O.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
|
@@ -1,20 +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 type { Browser } from 'playwright-core';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Disposable handle returned by {@link createTunneledBrowserAsync}.
|
|
8
|
-
* @beta
|
|
9
|
-
*/
|
|
10
|
-
export interface IDisposableTunneledBrowser {
|
|
11
|
-
/**
|
|
12
|
-
* The connected Playwright Browser instance.
|
|
13
|
-
*/
|
|
14
|
-
browser: Browser;
|
|
15
|
-
/**
|
|
16
|
-
* Async dispose method that closes the browser connection.
|
|
17
|
-
* Called automatically when using `await using` syntax.
|
|
18
|
-
*/
|
|
19
|
-
[Symbol.asyncDispose]: () => Promise<void>;
|
|
20
|
-
}
|
|
@@ -1,37 +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 type { LaunchOptions } from 'playwright-core';
|
|
5
|
-
|
|
6
|
-
import type { BrowserName } from '../PlaywrightBrowserTunnel';
|
|
7
|
-
|
|
8
|
-
export interface IHandshake {
|
|
9
|
-
action: 'handshake';
|
|
10
|
-
browserName: BrowserName;
|
|
11
|
-
launchOptions: LaunchOptions;
|
|
12
|
-
playwrightVersion: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface IHandshakeAck {
|
|
16
|
-
action: 'handshakeAck';
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Disposable handle returned by {@link tunneledBrowserConnection}.
|
|
21
|
-
* @beta
|
|
22
|
-
*/
|
|
23
|
-
export interface IDisposableTunneledBrowserConnection {
|
|
24
|
-
/**
|
|
25
|
-
* The WebSocket endpoint URL that the local Playwright client should connect to.
|
|
26
|
-
*/
|
|
27
|
-
remoteEndpoint: string;
|
|
28
|
-
/**
|
|
29
|
-
* Dispose method that closes the WebSocket servers.
|
|
30
|
-
* Called automatically when using `using` syntax.
|
|
31
|
-
*/
|
|
32
|
-
[Symbol.dispose]: () => void;
|
|
33
|
-
/**
|
|
34
|
-
* Promise that resolves when the remote WebSocket server closes.
|
|
35
|
-
*/
|
|
36
|
-
closePromise: Promise<void>;
|
|
37
|
-
}
|
|
@@ -1,52 +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 type { Browser, LaunchOptions } from 'playwright-core';
|
|
5
|
-
import playwright from 'playwright-core';
|
|
6
|
-
|
|
7
|
-
import type { ITerminal } from '@rushstack/terminal';
|
|
8
|
-
import { ConsoleTerminalProvider, Terminal } from '@rushstack/terminal';
|
|
9
|
-
|
|
10
|
-
import type { BrowserName } from '../PlaywrightBrowserTunnel';
|
|
11
|
-
import { DEFAULT_LISTEN_PORT } from './constants';
|
|
12
|
-
import type { IDisposableTunneledBrowser } from './ITunneledBrowser';
|
|
13
|
-
import type { IDisposableTunneledBrowserConnection } from './ITunneledBrowserConnection';
|
|
14
|
-
import { tunneledBrowserConnection } from './TunneledBrowserConnection';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Creates a Playwright Browser instance connected via a tunneled WebSocket connection.
|
|
18
|
-
* @beta
|
|
19
|
-
*/
|
|
20
|
-
export async function createTunneledBrowserAsync(
|
|
21
|
-
browserName: BrowserName,
|
|
22
|
-
launchOptions: LaunchOptions,
|
|
23
|
-
logger?: ITerminal,
|
|
24
|
-
port: number = DEFAULT_LISTEN_PORT
|
|
25
|
-
): Promise<IDisposableTunneledBrowser> {
|
|
26
|
-
// Establish the tunnel first (remoteEndpoint here refers to local proxy endpoint for connect())
|
|
27
|
-
|
|
28
|
-
if (!logger) {
|
|
29
|
-
const terminalProvider: ConsoleTerminalProvider = new ConsoleTerminalProvider();
|
|
30
|
-
logger = new Terminal(terminalProvider);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const connection: IDisposableTunneledBrowserConnection = await tunneledBrowserConnection(logger, port);
|
|
34
|
-
const { remoteEndpoint } = connection;
|
|
35
|
-
// Append query params for browser and launchOptions
|
|
36
|
-
const urlObj: URL = new URL(remoteEndpoint);
|
|
37
|
-
urlObj.searchParams.set('browser', browserName);
|
|
38
|
-
urlObj.searchParams.set('launchOptions', JSON.stringify(launchOptions || {}));
|
|
39
|
-
const connectEndpoint: string = urlObj.toString();
|
|
40
|
-
const browser: Browser = await playwright[browserName].connect(connectEndpoint);
|
|
41
|
-
logger.writeLine(`Connected to remote browser at ${connectEndpoint}`);
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
browser,
|
|
45
|
-
async [Symbol.asyncDispose]() {
|
|
46
|
-
logger.writeLine('Disposing browser');
|
|
47
|
-
await browser.close();
|
|
48
|
-
// Dispose the tunnel connection after browser is closed
|
|
49
|
-
connection[Symbol.dispose]();
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
}
|
|
@@ -1,232 +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 type { LaunchOptions } from 'playwright-core';
|
|
5
|
-
import playwrightPackageJson from 'playwright-core/package.json';
|
|
6
|
-
import type { RawData } from 'ws';
|
|
7
|
-
import { WebSocket, WebSocketServer } from 'ws';
|
|
8
|
-
|
|
9
|
-
import type { ITerminal } from '@rushstack/terminal';
|
|
10
|
-
|
|
11
|
-
import { HttpServer } from '../HttpServer';
|
|
12
|
-
import type { BrowserName } from '../PlaywrightBrowserTunnel';
|
|
13
|
-
import {
|
|
14
|
-
getNormalizedErrorString,
|
|
15
|
-
getWebSocketCloseReason,
|
|
16
|
-
getWebSocketReadyStateString,
|
|
17
|
-
WebSocketCloseCode
|
|
18
|
-
} from '../utilities';
|
|
19
|
-
import type {
|
|
20
|
-
IDisposableTunneledBrowserConnection,
|
|
21
|
-
IHandshake,
|
|
22
|
-
IHandshakeAck
|
|
23
|
-
} from './ITunneledBrowserConnection';
|
|
24
|
-
import { DEFAULT_LISTEN_PORT, SUPPORTED_BROWSER_NAMES } from './constants';
|
|
25
|
-
|
|
26
|
-
const { version: playwrightVersion } = playwrightPackageJson;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Creates a tunneled WebSocket endpoint that a local Playwright client can connect to.
|
|
30
|
-
* @beta
|
|
31
|
-
*/
|
|
32
|
-
export async function tunneledBrowserConnection(
|
|
33
|
-
logger: ITerminal,
|
|
34
|
-
port: number = DEFAULT_LISTEN_PORT
|
|
35
|
-
): Promise<IDisposableTunneledBrowserConnection> {
|
|
36
|
-
// Server that remote peer (actual browser host) connects to
|
|
37
|
-
const remoteWsServer: WebSocketServer = new WebSocketServer({ port });
|
|
38
|
-
// Local HTTP + WebSocket server where the playwright client will connect providing params
|
|
39
|
-
const httpServer: HttpServer = new HttpServer(logger);
|
|
40
|
-
await httpServer.listenAsync();
|
|
41
|
-
logger.writeLine(`Remote WebSocket server listening on ws://localhost:${port}`);
|
|
42
|
-
|
|
43
|
-
const localProxyWs: WebSocketServer = httpServer.wsServer;
|
|
44
|
-
const localProxyWsEndpoint: string = httpServer.endpoint;
|
|
45
|
-
|
|
46
|
-
let browserName: BrowserName | undefined;
|
|
47
|
-
let launchOptions: LaunchOptions | undefined;
|
|
48
|
-
let remoteSocket: WebSocket | undefined;
|
|
49
|
-
let handshakeAck: boolean = false;
|
|
50
|
-
let handshakeSent: boolean = false;
|
|
51
|
-
|
|
52
|
-
function maybeSendHandshake(): void {
|
|
53
|
-
if (!handshakeSent && remoteSocket && browserName && launchOptions) {
|
|
54
|
-
const handshake: IHandshake = {
|
|
55
|
-
action: 'handshake',
|
|
56
|
-
browserName,
|
|
57
|
-
launchOptions,
|
|
58
|
-
playwrightVersion
|
|
59
|
-
};
|
|
60
|
-
// Log handshake without 'headless' to avoid confusion (tunnel enforces headless: false)
|
|
61
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
62
|
-
const { headless, ...logOptions } = launchOptions;
|
|
63
|
-
const logHandshake: Omit<IHandshake, 'launchOptions'> & {
|
|
64
|
-
launchOptions: Omit<LaunchOptions, 'headless'>;
|
|
65
|
-
} = {
|
|
66
|
-
...handshake,
|
|
67
|
-
launchOptions: logOptions
|
|
68
|
-
};
|
|
69
|
-
logger.writeLine(`Sending handshake to remote: ${JSON.stringify(logHandshake)}`);
|
|
70
|
-
handshakeSent = true;
|
|
71
|
-
remoteSocket.send(JSON.stringify(handshake));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return await new Promise((resolve) => {
|
|
76
|
-
remoteWsServer.on('error', (error) => {
|
|
77
|
-
logger.writeErrorLine(`Remote WebSocket server error: ${error}`);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
remoteWsServer.on('close', () => {
|
|
81
|
-
logger.writeLine('Remote WebSocket server closed');
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
const bufferedLocalMessages: Array<RawData> = [];
|
|
85
|
-
|
|
86
|
-
remoteWsServer.on('connection', (ws) => {
|
|
87
|
-
logger.writeLine('Remote websocket connected');
|
|
88
|
-
remoteSocket = ws;
|
|
89
|
-
handshakeAck = false;
|
|
90
|
-
maybeSendHandshake();
|
|
91
|
-
|
|
92
|
-
ws.on('message', (message) => {
|
|
93
|
-
if (!handshakeAck) {
|
|
94
|
-
try {
|
|
95
|
-
const receivedHandshake: IHandshakeAck = JSON.parse(message.toString());
|
|
96
|
-
if (receivedHandshake.action === 'handshakeAck') {
|
|
97
|
-
handshakeAck = true;
|
|
98
|
-
logger.writeLine('Received handshakeAck from remote');
|
|
99
|
-
} else {
|
|
100
|
-
logger.writeErrorLine('Invalid handshake ack message');
|
|
101
|
-
ws.close(WebSocketCloseCode.PROTOCOL_ERROR, 'Invalid handshake ack');
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
} catch (e) {
|
|
105
|
-
logger.writeErrorLine(`Failed parsing handshake ack: ${e}`);
|
|
106
|
-
ws.close(WebSocketCloseCode.PROTOCOL_ERROR, 'Failed parsing handshake');
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
// Resolve only once local proxy available and handshake acknowledged
|
|
110
|
-
if (handshakeAck) {
|
|
111
|
-
// Flush any buffered local messages now that tunnel is active
|
|
112
|
-
const activeRemote: WebSocket | undefined = remoteSocket;
|
|
113
|
-
if (activeRemote && activeRemote.readyState === WebSocket.OPEN) {
|
|
114
|
-
while (bufferedLocalMessages.length > 0) {
|
|
115
|
-
const m: Buffer | ArrayBuffer | Buffer[] | string | undefined = bufferedLocalMessages.shift();
|
|
116
|
-
if (m !== undefined) {
|
|
117
|
-
logger.writeLine(`Flushing buffered local message to remote: ${m}`);
|
|
118
|
-
activeRemote.send(m);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
} else {
|
|
124
|
-
// Forward from remote to all local clients
|
|
125
|
-
localProxyWs.clients.forEach((client) => {
|
|
126
|
-
if (client.readyState === WebSocket.OPEN) {
|
|
127
|
-
client.send(message);
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
ws.on('close', (code: number, reason: Buffer) => {
|
|
134
|
-
const reasonStr: string = reason.toString() || 'no reason provided';
|
|
135
|
-
const codeDescription: string = getWebSocketCloseReason(code);
|
|
136
|
-
logger.writeDebugLine(
|
|
137
|
-
`Remote websocket closed - code: ${code} (${codeDescription}), reason: ${reasonStr}`
|
|
138
|
-
);
|
|
139
|
-
logger.writeDebugLine(
|
|
140
|
-
` Connection state at close: handshakeSent=${handshakeSent}, handshakeAck=${handshakeAck}`
|
|
141
|
-
);
|
|
142
|
-
logger.writeDebugLine(` Buffered messages pending: ${bufferedLocalMessages.length}`);
|
|
143
|
-
});
|
|
144
|
-
ws.on('error', (err: Error) => {
|
|
145
|
-
logger.writeErrorLine(`Remote websocket error: ${getNormalizedErrorString(err)}`);
|
|
146
|
-
logger.writeErrorLine(` Socket readyState: ${getWebSocketReadyStateString(ws.readyState)}`);
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
localProxyWs.on('connection', (localWs, request) => {
|
|
151
|
-
try {
|
|
152
|
-
const urlString: string | undefined = request?.url;
|
|
153
|
-
if (urlString) {
|
|
154
|
-
const parsed: URL = new URL(urlString, 'http://localhost');
|
|
155
|
-
logger.writeLine(`Local client connected with query params: ${parsed.searchParams.toString()}`);
|
|
156
|
-
const bName: string | null = parsed.searchParams.get('browser');
|
|
157
|
-
if (bName && SUPPORTED_BROWSER_NAMES.has(bName)) {
|
|
158
|
-
browserName = bName as BrowserName;
|
|
159
|
-
}
|
|
160
|
-
const launchOptionsParam: string | null = parsed.searchParams.get('launchOptions');
|
|
161
|
-
if (launchOptionsParam) {
|
|
162
|
-
try {
|
|
163
|
-
launchOptions = JSON.parse(launchOptionsParam);
|
|
164
|
-
} catch (e) {
|
|
165
|
-
logger.writeErrorLine('Invalid launchOptions JSON provided');
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
} catch (e) {
|
|
170
|
-
logger.writeErrorLine(`Error parsing local connection query params: ${e}`);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (!browserName) {
|
|
174
|
-
const supportedBrowsersString: string = Array.from(SUPPORTED_BROWSER_NAMES).join('|');
|
|
175
|
-
logger.writeErrorLine(`browser query param required (${supportedBrowsersString})`);
|
|
176
|
-
localWs.close(WebSocketCloseCode.PROTOCOL_ERROR, 'Missing browser param');
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
if (!launchOptions) {
|
|
180
|
-
launchOptions = {} as LaunchOptions; // default empty if not provided
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
maybeSendHandshake();
|
|
184
|
-
|
|
185
|
-
localWs.on('message', (message) => {
|
|
186
|
-
if (handshakeAck && remoteSocket?.readyState === WebSocket.OPEN) {
|
|
187
|
-
remoteSocket.send(message);
|
|
188
|
-
} else {
|
|
189
|
-
// Buffer until handshakeAck to avoid losing early protocol messages from Playwright
|
|
190
|
-
bufferedLocalMessages.push(message);
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
localWs.on('close', (code: number, reason: Buffer) => {
|
|
194
|
-
const reasonStr: string = reason.toString() || 'no reason provided';
|
|
195
|
-
const codeDescription: string = getWebSocketCloseReason(code);
|
|
196
|
-
logger.writeDebugLine(
|
|
197
|
-
`Local client websocket closed - code: ${code} (${codeDescription}), reason: ${reasonStr}`
|
|
198
|
-
);
|
|
199
|
-
logger.writeDebugLine(
|
|
200
|
-
` Remote socket state: ${remoteSocket ? getWebSocketReadyStateString(remoteSocket.readyState) : 'undefined'}`
|
|
201
|
-
);
|
|
202
|
-
logger.writeDebugLine(` handshakeAck: ${handshakeAck}`);
|
|
203
|
-
});
|
|
204
|
-
localWs.on('error', (err: Error) => {
|
|
205
|
-
logger.writeErrorLine(`Local client websocket error: ${getNormalizedErrorString(err)}`);
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
// Resolve immediately so caller can initiate local connection with query params (handshake completes later)
|
|
210
|
-
resolve({
|
|
211
|
-
remoteEndpoint: localProxyWsEndpoint,
|
|
212
|
-
[Symbol.dispose]() {
|
|
213
|
-
try {
|
|
214
|
-
remoteWsServer.close();
|
|
215
|
-
} catch {
|
|
216
|
-
// ignore errors during remote WebSocket server shutdown
|
|
217
|
-
}
|
|
218
|
-
try {
|
|
219
|
-
httpServer[Symbol.dispose]();
|
|
220
|
-
} catch {
|
|
221
|
-
// ignore errors during HTTP/WebSocket server shutdown
|
|
222
|
-
}
|
|
223
|
-
},
|
|
224
|
-
// eslint-disable-next-line promise/param-names
|
|
225
|
-
closePromise: new Promise<void>((resolve2) => {
|
|
226
|
-
remoteWsServer.once('close', () => {
|
|
227
|
-
resolve2();
|
|
228
|
-
});
|
|
229
|
-
})
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
}
|
|
@@ -1,5 +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
|
-
export const SUPPORTED_BROWSER_NAMES: Set<string> = new Set(['chromium', 'firefox', 'webkit']);
|
|
5
|
-
export const DEFAULT_LISTEN_PORT: number = 56767;
|
|
@@ -1,8 +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
|
-
export { createTunneledBrowserAsync } from './TunneledBrowser';
|
|
5
|
-
export { tunneledBrowserConnection } from './TunneledBrowserConnection';
|
|
6
|
-
|
|
7
|
-
export type { IDisposableTunneledBrowser } from './ITunneledBrowser';
|
|
8
|
-
export type { IDisposableTunneledBrowserConnection } from './ITunneledBrowserConnection';
|
package/src/utilities.ts
DELETED
|
@@ -1,136 +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 { tmpdir } from 'node:os';
|
|
5
|
-
|
|
6
|
-
import { FileSystem } from '@rushstack/node-core-library';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The filename used to indicate that the Playwright Local Browser Server extension is installed.
|
|
10
|
-
* @beta
|
|
11
|
-
*/
|
|
12
|
-
export const EXTENSION_INSTALLED_FILENAME: string =
|
|
13
|
-
'.playwright-local-browser-server-extension-installed.txt';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Helper to determine if the Playwright Local Browser Server extension is installed. This checks for the
|
|
17
|
-
* existence of a well-known file in the OS temp directory.
|
|
18
|
-
* @beta
|
|
19
|
-
*/
|
|
20
|
-
export async function isExtensionInstalledAsync(): Promise<boolean> {
|
|
21
|
-
// Read file from os.tempdir() + '/.playwright-local-browser-server-extension-installed'
|
|
22
|
-
const tempDir: string = tmpdir();
|
|
23
|
-
|
|
24
|
-
const extensionInstalledFilePath: string = `${tempDir}/${EXTENSION_INSTALLED_FILENAME}`;
|
|
25
|
-
const doesExist: boolean = FileSystem.exists(extensionInstalledFilePath);
|
|
26
|
-
|
|
27
|
-
// check if file exists
|
|
28
|
-
return doesExist;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Normalizes an error to a string for logging purposes.
|
|
33
|
-
* @beta
|
|
34
|
-
*/
|
|
35
|
-
export function getNormalizedErrorString(error: unknown): string {
|
|
36
|
-
if (error instanceof Error) {
|
|
37
|
-
if (error.stack) {
|
|
38
|
-
return error.stack;
|
|
39
|
-
}
|
|
40
|
-
return error.message;
|
|
41
|
-
}
|
|
42
|
-
return String(error);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* WebSocket close codes as defined by RFC 6455.
|
|
47
|
-
* @see {@link https://datatracker.ietf.org/doc/html/rfc6455#section-11.7}
|
|
48
|
-
* @beta
|
|
49
|
-
*/
|
|
50
|
-
export const WebSocketCloseCode: {
|
|
51
|
-
/** Normal closure; the connection successfully completed. */
|
|
52
|
-
readonly NORMAL_CLOSURE: 1000;
|
|
53
|
-
/** Endpoint is going away (e.g., server shutting down, browser navigating away). */
|
|
54
|
-
readonly GOING_AWAY: 1001;
|
|
55
|
-
/** Protocol error encountered. */
|
|
56
|
-
readonly PROTOCOL_ERROR: 1002;
|
|
57
|
-
/** Received data type that cannot be accepted (e.g., text-only endpoint received binary). */
|
|
58
|
-
readonly UNSUPPORTED_DATA: 1003;
|
|
59
|
-
/** No status code was provided even though one was expected. */
|
|
60
|
-
readonly NO_STATUS_RECEIVED: 1005;
|
|
61
|
-
/** Connection was closed abnormally (e.g., without sending a close frame). */
|
|
62
|
-
readonly ABNORMAL_CLOSURE: 1006;
|
|
63
|
-
/** Received message data inconsistent with the message type. */
|
|
64
|
-
readonly INVALID_PAYLOAD: 1007;
|
|
65
|
-
/** Received a message that violates policy. */
|
|
66
|
-
readonly POLICY_VIOLATION: 1008;
|
|
67
|
-
/** Received a message that is too big to process. */
|
|
68
|
-
readonly MESSAGE_TOO_BIG: 1009;
|
|
69
|
-
/** Server encountered an unexpected condition that prevented it from fulfilling the request. */
|
|
70
|
-
readonly INTERNAL_ERROR: 1011;
|
|
71
|
-
/** Connection was closed due to TLS handshake failure. */
|
|
72
|
-
readonly TLS_HANDSHAKE_FAILED: 1015;
|
|
73
|
-
} = {
|
|
74
|
-
NORMAL_CLOSURE: 1000,
|
|
75
|
-
GOING_AWAY: 1001,
|
|
76
|
-
PROTOCOL_ERROR: 1002,
|
|
77
|
-
UNSUPPORTED_DATA: 1003,
|
|
78
|
-
NO_STATUS_RECEIVED: 1005,
|
|
79
|
-
ABNORMAL_CLOSURE: 1006,
|
|
80
|
-
INVALID_PAYLOAD: 1007,
|
|
81
|
-
POLICY_VIOLATION: 1008,
|
|
82
|
-
MESSAGE_TOO_BIG: 1009,
|
|
83
|
-
INTERNAL_ERROR: 1011,
|
|
84
|
-
TLS_HANDSHAKE_FAILED: 1015
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Type for WebSocket close code values.
|
|
89
|
-
* @beta
|
|
90
|
-
*/
|
|
91
|
-
export type WebSocketCloseCodeValue = (typeof WebSocketCloseCode)[keyof typeof WebSocketCloseCode];
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Human-readable descriptions for WebSocket close codes.
|
|
95
|
-
* @beta
|
|
96
|
-
*/
|
|
97
|
-
export const WebSocketCloseCodeDescriptions: Record<WebSocketCloseCodeValue, string> = {
|
|
98
|
-
[WebSocketCloseCode.NORMAL_CLOSURE]: 'Normal Closure',
|
|
99
|
-
[WebSocketCloseCode.GOING_AWAY]: 'Going Away',
|
|
100
|
-
[WebSocketCloseCode.PROTOCOL_ERROR]: 'Protocol Error',
|
|
101
|
-
[WebSocketCloseCode.UNSUPPORTED_DATA]: 'Unsupported Data',
|
|
102
|
-
[WebSocketCloseCode.NO_STATUS_RECEIVED]: 'No Status Received',
|
|
103
|
-
[WebSocketCloseCode.ABNORMAL_CLOSURE]: 'Abnormal Closure (connection lost)',
|
|
104
|
-
[WebSocketCloseCode.INVALID_PAYLOAD]: 'Invalid Payload',
|
|
105
|
-
[WebSocketCloseCode.POLICY_VIOLATION]: 'Policy Violation',
|
|
106
|
-
[WebSocketCloseCode.MESSAGE_TOO_BIG]: 'Message Too Big',
|
|
107
|
-
[WebSocketCloseCode.INTERNAL_ERROR]: 'Internal Error',
|
|
108
|
-
[WebSocketCloseCode.TLS_HANDSHAKE_FAILED]: 'TLS Handshake Failed'
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Returns a human-readable description for a WebSocket close code.
|
|
113
|
-
* @beta
|
|
114
|
-
*/
|
|
115
|
-
export function getWebSocketCloseReason(code: number): string {
|
|
116
|
-
return WebSocketCloseCodeDescriptions[code as WebSocketCloseCodeValue] || 'Unknown';
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Returns a human-readable string for a WebSocket ready state.
|
|
121
|
-
* @beta
|
|
122
|
-
*/
|
|
123
|
-
export function getWebSocketReadyStateString(readyState: number): string {
|
|
124
|
-
switch (readyState) {
|
|
125
|
-
case 0:
|
|
126
|
-
return 'CONNECTING';
|
|
127
|
-
case 1:
|
|
128
|
-
return 'OPEN';
|
|
129
|
-
case 2:
|
|
130
|
-
return 'CLOSING';
|
|
131
|
-
case 3:
|
|
132
|
-
return 'CLOSED';
|
|
133
|
-
default:
|
|
134
|
-
return `UNKNOWN(${readyState})`;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"cacheVersion": "9.37.0_v22.21.1",
|
|
3
|
-
"fileVersions": [
|
|
4
|
-
[
|
|
5
|
-
"HttpServer.ts",
|
|
6
|
-
"eb5d3c70d2744adfbd44448fe2fae2b0a6413b15bb338fd31af7ecade290c973_Q57tkjZtaaMkmlD1DBUjScEtgSo="
|
|
7
|
-
],
|
|
8
|
-
[
|
|
9
|
-
"LaunchOptionsValidator.ts",
|
|
10
|
-
"36f10ef5bba6f95e0f332c1aab5a344c6e1475f8d35abb30a74143cdfd42a537_Q57tkjZtaaMkmlD1DBUjScEtgSo="
|
|
11
|
-
],
|
|
12
|
-
[
|
|
13
|
-
"utilities.ts",
|
|
14
|
-
"f24e93ae9da2ced3e3e5b3d4b7becddcf80ac8678775c673cc80a63045e9a246_Q57tkjZtaaMkmlD1DBUjScEtgSo="
|
|
15
|
-
],
|
|
16
|
-
[
|
|
17
|
-
"PlaywrightBrowserTunnel.ts",
|
|
18
|
-
"1bbea2c477cd1510d00e14a14fbec331f491dd2f058e2146671cb08385da8e09_Q57tkjZtaaMkmlD1DBUjScEtgSo="
|
|
19
|
-
],
|
|
20
|
-
[
|
|
21
|
-
"tunneledBrowserConnection/constants.ts",
|
|
22
|
-
"869309171fd2db0c9aaeb1003be41243d026b23c1715de8e53afe8b30edd1f39_Q57tkjZtaaMkmlD1DBUjScEtgSo="
|
|
23
|
-
],
|
|
24
|
-
[
|
|
25
|
-
"tunneledBrowserConnection/ITunneledBrowser.ts",
|
|
26
|
-
"f69368b63d693a2c39804340262e6f4262c44a3cba1a73ee34084634d44fd4ef_Q57tkjZtaaMkmlD1DBUjScEtgSo="
|
|
27
|
-
],
|
|
28
|
-
[
|
|
29
|
-
"tunneledBrowserConnection/ITunneledBrowserConnection.ts",
|
|
30
|
-
"0a38e3d400fbbaa2c2e46c7671791a21a6ca5f64c6e0179cb6763f66fd2be8d3_Q57tkjZtaaMkmlD1DBUjScEtgSo="
|
|
31
|
-
],
|
|
32
|
-
[
|
|
33
|
-
"tunneledBrowserConnection/TunneledBrowserConnection.ts",
|
|
34
|
-
"9b61eeb3223a7e24a6cece972a31c4ec06cf8d517b5c686fe24a5708642306b6_Q57tkjZtaaMkmlD1DBUjScEtgSo="
|
|
35
|
-
],
|
|
36
|
-
[
|
|
37
|
-
"tunneledBrowserConnection/TunneledBrowser.ts",
|
|
38
|
-
"2b1763d3a9069360f0eaf654d86c9a147e749f51a0622530606519472af1ed61_Q57tkjZtaaMkmlD1DBUjScEtgSo="
|
|
39
|
-
],
|
|
40
|
-
[
|
|
41
|
-
"tunneledBrowserConnection/index.ts",
|
|
42
|
-
"7120be95e2c956b5b31ec8dc46a2824b0bf8058f36ea7a43ac60c1ccad23dca2_Q57tkjZtaaMkmlD1DBUjScEtgSo="
|
|
43
|
-
],
|
|
44
|
-
[
|
|
45
|
-
"index.ts",
|
|
46
|
-
"24a883b07dbd0c309fa5f83653a48f3ac849200808fbe3872f34b11c99ea1668_Q57tkjZtaaMkmlD1DBUjScEtgSo="
|
|
47
|
-
]
|
|
48
|
-
],
|
|
49
|
-
"filesHash": "yJgnU3yxb7-XPq6SpVUP-w"
|
|
50
|
-
}
|