Skip to content

Commit ce7aa7a

Browse files
authored
feat(firefox): migrate to the pipe channel (#4068)
1 parent e6869ed commit ce7aa7a

File tree

7 files changed

+21
-38
lines changed

7 files changed

+21
-38
lines changed

browsers.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
{
1010
"name": "firefox",
11-
"revision": "1182",
11+
"revision": "1184",
1212
"download": true
1313
},
1414
{

src/server/browserType.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import * as path from 'path';
2020
import * as util from 'util';
2121
import { BrowserContext, normalizeProxySettings, validateBrowserContextOptions } from './browserContext';
2222
import * as browserPaths from '../utils/browserPaths';
23-
import { ConnectionTransport, WebSocketTransport } from './transport';
23+
import { ConnectionTransport } from './transport';
2424
import { BrowserOptions, Browser, BrowserProcess } from './browser';
25-
import { launchProcess, Env, waitForLine, envArrayToObject } from './processLauncher';
25+
import { launchProcess, Env, envArrayToObject } from './processLauncher';
2626
import { PipeTransport } from './pipeTransport';
2727
import { Progress, ProgressController } from './progress';
2828
import * as types from './types';
@@ -35,22 +35,18 @@ const mkdtempAsync = util.promisify(fs.mkdtemp);
3535
const existsAsync = (path: string): Promise<boolean> => new Promise(resolve => fs.stat(path, err => resolve(!err)));
3636
const DOWNLOADS_FOLDER = path.join(os.tmpdir(), 'playwright_downloads-');
3737

38-
type WebSocketNotPipe = { webSocketRegex: RegExp, stream: 'stdout' | 'stderr' };
39-
4038
export abstract class BrowserType {
4139
private _name: string;
4240
private _executablePath: string;
43-
private _webSocketNotPipe: WebSocketNotPipe | null;
4441
private _browserDescriptor: browserPaths.BrowserDescriptor;
4542
readonly _browserPath: string;
4643

47-
constructor(packagePath: string, browser: browserPaths.BrowserDescriptor, webSocketOrPipe: WebSocketNotPipe | null) {
44+
constructor(packagePath: string, browser: browserPaths.BrowserDescriptor) {
4845
this._name = browser.name;
4946
const browsersPath = browserPaths.browsersPath(packagePath);
5047
this._browserDescriptor = browser;
5148
this._browserPath = browserPaths.browserDirectory(browsersPath, browser);
5249
this._executablePath = browserPaths.executablePath(this._browserPath, browser) || '';
53-
this._webSocketNotPipe = webSocketOrPipe;
5450
}
5551

5652
executablePath(): string {
@@ -175,7 +171,6 @@ export abstract class BrowserType {
175171
handleSIGTERM,
176172
handleSIGHUP,
177173
progress,
178-
pipe: !this._webSocketNotPipe,
179174
tempDirectories,
180175
attemptToGracefullyClose: async () => {
181176
if ((options as any).__testHookGracefullyClose)
@@ -198,14 +193,8 @@ export abstract class BrowserType {
198193
};
199194
progress.cleanupWhenAborted(() => browserProcess && closeOrKill(browserProcess, progress.timeUntilDeadline()));
200195

201-
if (this._webSocketNotPipe) {
202-
const match = await waitForLine(progress, launchedProcess, this._webSocketNotPipe.stream === 'stdout' ? launchedProcess.stdout : launchedProcess.stderr, this._webSocketNotPipe.webSocketRegex);
203-
const innerEndpoint = match[1];
204-
transport = await WebSocketTransport.connect(progress, innerEndpoint);
205-
} else {
206-
const stdio = launchedProcess.stdio as unknown as [NodeJS.ReadableStream, NodeJS.WritableStream, NodeJS.WritableStream, NodeJS.WritableStream, NodeJS.ReadableStream];
207-
transport = new PipeTransport(stdio[3], stdio[4]);
208-
}
196+
const stdio = launchedProcess.stdio as unknown as [NodeJS.ReadableStream, NodeJS.WritableStream, NodeJS.WritableStream, NodeJS.WritableStream, NodeJS.ReadableStream];
197+
transport = new PipeTransport(stdio[3], stdio[4]);
209198
return { browserProcess, downloadsPath, transport };
210199
}
211200

src/server/chromium/chromium.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,9 @@ import { isDebugMode, getFromENV } from '../../utils/utils';
3131

3232
export class Chromium extends BrowserType {
3333
private _devtools: CRDevTools | undefined;
34-
private _debugPort: number | undefined;
3534

3635
constructor(packagePath: string, browser: BrowserDescriptor) {
37-
const debugPortStr = getFromENV('PLAYWRIGHT_CHROMIUM_DEBUG_PORT');
38-
const debugPort: number | undefined = debugPortStr ? +debugPortStr : undefined;
39-
if (debugPort !== undefined) {
40-
if (Number.isNaN(debugPort))
41-
throw new Error(`PLAYWRIGHT_CHROMIUM_DEBUG_PORT must be a number, but is set to "${debugPortStr}"`);
42-
}
43-
44-
super(packagePath, browser, debugPort ? { webSocketRegex: /^DevTools listening on (ws:\/\/.*)$/, stream: 'stderr' } : null);
45-
this._debugPort = debugPort;
36+
super(packagePath, browser);
4637
if (isDebugMode())
4738
this._devtools = this._createDevTools();
4839
}
@@ -110,10 +101,16 @@ export class Chromium extends BrowserType {
110101
throw new Error('Arguments can not specify page to be opened');
111102
const chromeArguments = [...DEFAULT_ARGS];
112103
chromeArguments.push(`--user-data-dir=${userDataDir}`);
113-
if (this._debugPort !== undefined)
114-
chromeArguments.push('--remote-debugging-port=' + this._debugPort);
115-
else
116-
chromeArguments.push('--remote-debugging-pipe');
104+
105+
const debugPortStr = getFromENV('PLAYWRIGHT_CHROMIUM_DEBUG_PORT');
106+
if (debugPortStr) {
107+
const debugPort = +debugPortStr;
108+
if (Number.isNaN(debugPort))
109+
throw new Error(`PLAYWRIGHT_CHROMIUM_DEBUG_PORT must be a number, but is set to "${debugPortStr}"`);
110+
chromeArguments.push('--remote-debugging-port=' + debugPort);
111+
}
112+
113+
chromeArguments.push('--remote-debugging-pipe');
117114
if (options.devtools)
118115
chromeArguments.push('--auto-open-devtools-for-tabs');
119116
if (options.headless) {

src/server/electron/electron.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ export class Electron {
163163
handleSIGTERM,
164164
handleSIGHUP,
165165
progress,
166-
pipe: true,
167166
cwd: options.cwd,
168167
tempDirectories: [],
169168
attemptToGracefullyClose: () => app!.close(),

src/server/firefox/firefox.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ import * as types from '../types';
2929

3030
export class Firefox extends BrowserType {
3131
constructor(packagePath: string, browser: BrowserDescriptor) {
32-
const webSocketRegex = /^Juggler listening on (ws:\/\/.*)$/;
33-
super(packagePath, browser, { webSocketRegex, stream: 'stdout' });
32+
super(packagePath, browser);
3433
}
3534

3635
_connectToTransport(transport: ConnectionTransport, options: BrowserOptions): Promise<FFBrowser> {
@@ -82,7 +81,7 @@ export class Firefox extends BrowserType {
8281
firefoxArguments.push('-foreground');
8382
}
8483
firefoxArguments.push(`-profile`, userDataDir);
85-
firefoxArguments.push('-juggler', '0');
84+
firefoxArguments.push('-juggler-pipe');
8685
firefoxArguments.push(...args);
8786
if (isPersistent)
8887
firefoxArguments.push('about:blank');

src/server/processLauncher.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export type LaunchProcessOptions = {
3535
handleSIGINT?: boolean,
3636
handleSIGTERM?: boolean,
3737
handleSIGHUP?: boolean,
38-
pipe?: boolean,
3938
pipeStdin?: boolean,
4039
tempDirectories: string[],
4140

@@ -83,7 +82,7 @@ export async function launchProcess(options: LaunchProcessOptions): Promise<Laun
8382
const cleanup = () => helper.removeFolders(options.tempDirectories);
8483

8584
const progress = options.progress;
86-
const stdio: ('ignore' | 'pipe')[] = options.pipe ? ['ignore', 'pipe', 'pipe', 'pipe', 'pipe'] : ['ignore', 'pipe', 'pipe'];
85+
const stdio: ('ignore' | 'pipe')[] = ['ignore', 'pipe', 'pipe', 'pipe', 'pipe'];
8786
if (options.pipeStdin)
8887
stdio[0] = 'pipe';
8988
progress.log(`<launching> ${options.executablePath} ${options.args.join(' ')}`);

src/server/webkit/webkit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import * as types from '../types';
2727

2828
export class WebKit extends BrowserType {
2929
constructor(packagePath: string, browser: BrowserDescriptor) {
30-
super(packagePath, browser, null /* use pipe not websocket */);
30+
super(packagePath, browser);
3131
}
3232

3333
_connectToTransport(transport: ConnectionTransport, options: BrowserOptions): Promise<WKBrowser> {

0 commit comments

Comments
 (0)