mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
feat(debug): chromium debugging port (#2246)
This exposes Chromium remote debugging pipe under the port PLAYWRIGHT_CHROMIUM_DEBUG_PORT.
This commit is contained in:
parent
a26311a18a
commit
724d73c03b
@ -77,18 +77,20 @@ export interface BrowserType {
|
|||||||
const mkdtempAsync = util.promisify(fs.mkdtemp);
|
const mkdtempAsync = util.promisify(fs.mkdtemp);
|
||||||
const DOWNLOADS_FOLDER = path.join(os.tmpdir(), 'playwright_downloads-');
|
const DOWNLOADS_FOLDER = path.join(os.tmpdir(), 'playwright_downloads-');
|
||||||
|
|
||||||
|
type WebSocketNotPipe = { webSocketRegex: RegExp, stream: 'stdout' | 'stderr' };
|
||||||
|
|
||||||
export abstract class BrowserTypeBase implements BrowserType {
|
export abstract class BrowserTypeBase implements BrowserType {
|
||||||
private _name: string;
|
private _name: string;
|
||||||
private _executablePath: string | undefined;
|
private _executablePath: string | undefined;
|
||||||
private _webSocketRegexNotPipe: RegExp | null;
|
private _webSocketNotPipe: WebSocketNotPipe | null;
|
||||||
readonly _browserPath: string;
|
readonly _browserPath: string;
|
||||||
|
|
||||||
constructor(packagePath: string, browser: browserPaths.BrowserDescriptor, webSocketRegexNotPipe: RegExp | null) {
|
constructor(packagePath: string, browser: browserPaths.BrowserDescriptor, webSocketOrPipe: WebSocketNotPipe | null) {
|
||||||
this._name = browser.name;
|
this._name = browser.name;
|
||||||
const browsersPath = browserPaths.browsersPath(packagePath);
|
const browsersPath = browserPaths.browsersPath(packagePath);
|
||||||
this._browserPath = browserPaths.browserDirectory(browsersPath, browser);
|
this._browserPath = browserPaths.browserDirectory(browsersPath, browser);
|
||||||
this._executablePath = browserPaths.executablePath(this._browserPath, browser);
|
this._executablePath = browserPaths.executablePath(this._browserPath, browser);
|
||||||
this._webSocketRegexNotPipe = webSocketRegexNotPipe;
|
this._webSocketNotPipe = webSocketOrPipe;
|
||||||
}
|
}
|
||||||
|
|
||||||
executablePath(): string {
|
executablePath(): string {
|
||||||
@ -203,7 +205,7 @@ export abstract class BrowserTypeBase implements BrowserType {
|
|||||||
handleSIGTERM,
|
handleSIGTERM,
|
||||||
handleSIGHUP,
|
handleSIGHUP,
|
||||||
progress,
|
progress,
|
||||||
pipe: !this._webSocketRegexNotPipe,
|
pipe: !this._webSocketNotPipe,
|
||||||
tempDirectories,
|
tempDirectories,
|
||||||
attemptToGracefullyClose: async () => {
|
attemptToGracefullyClose: async () => {
|
||||||
if ((options as any).__testHookGracefullyClose)
|
if ((options as any).__testHookGracefullyClose)
|
||||||
@ -221,8 +223,8 @@ export abstract class BrowserTypeBase implements BrowserType {
|
|||||||
browserServer = new BrowserServer(launchedProcess, gracefullyClose, kill);
|
browserServer = new BrowserServer(launchedProcess, gracefullyClose, kill);
|
||||||
progress.cleanupWhenCanceled(() => browserServer && browserServer._closeOrKill(progress.deadline));
|
progress.cleanupWhenCanceled(() => browserServer && browserServer._closeOrKill(progress.deadline));
|
||||||
|
|
||||||
if (this._webSocketRegexNotPipe) {
|
if (this._webSocketNotPipe) {
|
||||||
const match = await waitForLine(progress, launchedProcess, launchedProcess.stdout, this._webSocketRegexNotPipe);
|
const match = await waitForLine(progress, launchedProcess, this._webSocketNotPipe.stream === 'stdout' ? launchedProcess.stdout : launchedProcess.stderr, this._webSocketNotPipe.webSocketRegex);
|
||||||
const innerEndpoint = match[1];
|
const innerEndpoint = match[1];
|
||||||
transport = await WebSocketTransport.connect(progress, innerEndpoint);
|
transport = await WebSocketTransport.connect(progress, innerEndpoint);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import { helper, assert } from '../helper';
|
import { helper, assert, getFromENV, logPolitely } from '../helper';
|
||||||
import { CRBrowser } from '../chromium/crBrowser';
|
import { CRBrowser } from '../chromium/crBrowser';
|
||||||
import * as ws from 'ws';
|
import * as ws from 'ws';
|
||||||
import { Env } from './processLauncher';
|
import { Env } from './processLauncher';
|
||||||
@ -32,9 +32,19 @@ import { BrowserOptions } from '../browser';
|
|||||||
|
|
||||||
export class Chromium extends BrowserTypeBase {
|
export class Chromium extends BrowserTypeBase {
|
||||||
private _devtools: CRDevTools | undefined;
|
private _devtools: CRDevTools | undefined;
|
||||||
|
private _debugPort: number | undefined;
|
||||||
|
|
||||||
constructor(packagePath: string, browser: BrowserDescriptor) {
|
constructor(packagePath: string, browser: BrowserDescriptor) {
|
||||||
super(packagePath, browser, null /* use pipe not websocket */);
|
const debugPortStr = getFromENV('PLAYWRIGHT_CHROMIUM_DEBUG_PORT');
|
||||||
|
const debugPort: number | undefined = debugPortStr ? +debugPortStr : undefined;
|
||||||
|
if (debugPort !== undefined) {
|
||||||
|
if (Number.isNaN(debugPort))
|
||||||
|
throw new Error(`PLAYWRIGHT_CHROMIUM_DEBUG_PORT must be a number, but is set to "${debugPortStr}"`);
|
||||||
|
logPolitely(`NOTE: Chromium will be launched in debug mode on port ${debugPort}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
super(packagePath, browser, debugPort ? { webSocketRegex: /^DevTools listening on (ws:\/\/.*)$/, stream: 'stderr' } : null);
|
||||||
|
this._debugPort = debugPort;
|
||||||
if (debugSupport.isDebugMode())
|
if (debugSupport.isDebugMode())
|
||||||
this._devtools = this._createDevTools();
|
this._devtools = this._createDevTools();
|
||||||
}
|
}
|
||||||
@ -79,7 +89,10 @@ export class Chromium extends BrowserTypeBase {
|
|||||||
throw new Error('Arguments can not specify page to be opened');
|
throw new Error('Arguments can not specify page to be opened');
|
||||||
const chromeArguments = [...DEFAULT_ARGS];
|
const chromeArguments = [...DEFAULT_ARGS];
|
||||||
chromeArguments.push(`--user-data-dir=${userDataDir}`);
|
chromeArguments.push(`--user-data-dir=${userDataDir}`);
|
||||||
chromeArguments.push('--remote-debugging-pipe');
|
if (this._debugPort !== undefined)
|
||||||
|
chromeArguments.push('--remote-debugging-port=' + this._debugPort);
|
||||||
|
else
|
||||||
|
chromeArguments.push('--remote-debugging-pipe');
|
||||||
if (devtools)
|
if (devtools)
|
||||||
chromeArguments.push('--auto-open-devtools-for-tabs');
|
chromeArguments.push('--auto-open-devtools-for-tabs');
|
||||||
if (headless) {
|
if (headless) {
|
||||||
|
|||||||
@ -32,8 +32,8 @@ import { BrowserDescriptor } from '../install/browserPaths';
|
|||||||
|
|
||||||
export class Firefox extends BrowserTypeBase {
|
export class Firefox extends BrowserTypeBase {
|
||||||
constructor(packagePath: string, browser: BrowserDescriptor) {
|
constructor(packagePath: string, browser: BrowserDescriptor) {
|
||||||
const websocketRegex = /^Juggler listening on (ws:\/\/.*)$/;
|
const webSocketRegex = /^Juggler listening on (ws:\/\/.*)$/;
|
||||||
super(packagePath, browser, websocketRegex /* use websocket not pipe */);
|
super(packagePath, browser, { webSocketRegex, stream: 'stdout' });
|
||||||
}
|
}
|
||||||
|
|
||||||
_connectToTransport(transport: ConnectionTransport, options: BrowserOptions): Promise<FFBrowser> {
|
_connectToTransport(transport: ConnectionTransport, options: BrowserOptions): Promise<FFBrowser> {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user