Skip to content

Commit 52766b2

Browse files
authored
Revert debug controller UI additions (#37661)
1 parent fb29112 commit 52766b2

File tree

24 files changed

+38
-739
lines changed

24 files changed

+38
-739
lines changed

.github/workflows/tests_primary.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ jobs:
187187
env:
188188
DEBUG: pw:install
189189
- run: npm run build
190-
- run: npx playwright install chromium firefox
190+
- run: npx playwright install chromium
191191
- name: Checkout extension
192192
run: git clone https://github.com/microsoft/playwright-vscode.git
193193
- name: Print extension revision

packages/playwright-core/src/browserServerImpl.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import * as validatorPrimitives from './protocol/validatorPrimitives';
2626
import { ProgressController } from './server/progress';
2727

2828
import type { BrowserServer, BrowserServerLauncher } from './client/browserType';
29-
import type { LaunchOptions, LaunchServerOptions, Logger } from './client/types';
29+
import type { LaunchServerOptions, Logger } from './client/types';
3030
import type { ProtocolLogger } from './server/types';
3131
import type { WebSocketEventEmitter } from './utilsBundle';
3232
import type { Browser } from './server/browser';
@@ -38,7 +38,7 @@ export class BrowserServerLauncherImpl implements BrowserServerLauncher {
3838
this._browserName = browserName;
3939
}
4040

41-
async launchServer(options: LaunchOptions & LaunchServerOptions & { _userDataDir?: string } = {}): Promise<BrowserServer> {
41+
async launchServer(options: LaunchServerOptions & { _sharedBrowser?: boolean, _userDataDir?: string } = {}): Promise<BrowserServer> {
4242
const playwright = createPlaywright({ sdkLanguage: 'javascript', isServer: true });
4343
// 1. Pre-launch the browser
4444
const metadata = { id: '', startTime: 0, endTime: 0, type: 'Internal', method: '', params: {}, log: [], internal: true };
@@ -78,14 +78,10 @@ export class BrowserServerLauncherImpl implements BrowserServerLauncher {
7878
throw e;
7979
}
8080

81-
return this.launchServerOnExistingBrowser(browser, options);
82-
}
83-
84-
async launchServerOnExistingBrowser(browser: Browser, options: LaunchServerOptions): Promise<BrowserServer> {
8581
const path = options.wsPath ? (options.wsPath.startsWith('/') ? options.wsPath : `/${options.wsPath}`) : `/${createGuid()}`;
8682

8783
// 2. Start the server
88-
const server = new PlaywrightServer({ mode: options._sharedBrowser ? 'launchServerShared' : 'launchServer', path, maxConnections: Infinity, preLaunchedBrowser: browser, debugController: options._debugController });
84+
const server = new PlaywrightServer({ mode: options._sharedBrowser ? 'launchServerShared' : 'launchServer', path, maxConnections: Infinity, preLaunchedBrowser: browser });
8985
const wsEndpoint = await server.listen(options.port, options.host);
9086

9187
// 3. Return the BrowserServer interface

packages/playwright-core/src/client/browser.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { mkdirIfNeeded } from './fileUtils';
2424

2525
import type { BrowserType } from './browserType';
2626
import type { Page } from './page';
27-
import type { BrowserContextOptions, LaunchOptions, LaunchServerOptions, Logger } from './types';
27+
import type { BrowserContextOptions, LaunchOptions, Logger } from './types';
2828
import type * as api from '../../types/types';
2929
import type * as channels from '@protocol/channels';
3030

@@ -146,17 +146,6 @@ export class Browser extends ChannelOwner<channels.BrowserChannel> implements ap
146146
return CDPSession.from((await this._channel.newBrowserCDPSession()).session);
147147
}
148148

149-
async _launchServer(options: LaunchServerOptions = {}) {
150-
const serverLauncher = this._browserType._serverLauncher;
151-
const browserImpl = this._connection.toImpl?.(this);
152-
if (!serverLauncher || !browserImpl)
153-
throw new Error('Launching server is not supported');
154-
return await serverLauncher.launchServerOnExistingBrowser(browserImpl, {
155-
_sharedBrowser: true,
156-
...options,
157-
});
158-
}
159-
160149
async startTracing(page?: Page, options: { path?: string; screenshots?: boolean; categories?: string[]; } = {}) {
161150
this._path = options.path;
162151
await this._channel.startTracing({ ...options, page: page ? page._channel : undefined });

packages/playwright-core/src/client/browserType.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ import type { ConnectOptions, LaunchOptions, LaunchPersistentContextOptions, Lau
3131
import type * as api from '../../types/types';
3232
import type * as channels from '@protocol/channels';
3333
import type { ChildProcess } from 'child_process';
34-
import type { Browser as BrowserImpl } from '../server/browser';
3534

3635
export interface BrowserServerLauncher {
37-
launchServer(options?: LaunchOptions & LaunchServerOptions): Promise<api.BrowserServer>;
38-
launchServerOnExistingBrowser(browser: BrowserImpl, options?: LaunchServerOptions): Promise<api.BrowserServer>;
36+
launchServer(options?: LaunchServerOptions): Promise<api.BrowserServer>;
3937
}
4038

4139
// This is here just for api generation and checking.

packages/playwright-core/src/client/types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,10 @@ export type ConnectOptions = {
104104
timeout?: number,
105105
logger?: Logger,
106106
};
107-
export type LaunchServerOptions = {
107+
export type LaunchServerOptions = LaunchOptions & {
108108
host?: string,
109109
port?: number,
110110
wsPath?: string,
111-
_debugController?: boolean;
112-
_sharedBrowser?: boolean;
113111
};
114112

115113
export type LaunchAndroidServerOptions = {

packages/playwright-core/src/protocol/validator.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -445,16 +445,6 @@ scheme.DebugControllerSetModeRequestedEvent = tObject({
445445
});
446446
scheme.DebugControllerStateChangedEvent = tObject({
447447
pageCount: tInt,
448-
browsers: tArray(tObject({
449-
id: tString,
450-
name: tString,
451-
channel: tOptional(tString),
452-
contexts: tArray(tObject({
453-
pages: tArray(tObject({
454-
url: tString,
455-
})),
456-
})),
457-
})),
458448
});
459449
scheme.DebugControllerSourceChangedEvent = tObject({
460450
text: tString,
@@ -475,7 +465,6 @@ scheme.DebugControllerSetReportStateChangedParams = tObject({
475465
});
476466
scheme.DebugControllerSetReportStateChangedResult = tOptional(tObject({}));
477467
scheme.DebugControllerSetRecorderModeParams = tObject({
478-
browserId: tOptional(tString),
479468
mode: tEnum(['inspecting', 'recording', 'none']),
480469
testIdAttributeName: tOptional(tString),
481470
generateAutoExpect: tOptional(tBoolean),
@@ -490,11 +479,6 @@ scheme.DebugControllerHideHighlightParams = tOptional(tObject({}));
490479
scheme.DebugControllerHideHighlightResult = tOptional(tObject({}));
491480
scheme.DebugControllerResumeParams = tOptional(tObject({}));
492481
scheme.DebugControllerResumeResult = tOptional(tObject({}));
493-
scheme.DebugControllerCloseBrowserParams = tObject({
494-
id: tString,
495-
reason: tOptional(tString),
496-
});
497-
scheme.DebugControllerCloseBrowserResult = tOptional(tObject({}));
498482
scheme.DebugControllerKillParams = tOptional(tObject({}));
499483
scheme.DebugControllerKillResult = tOptional(tObject({}));
500484
scheme.SocksSupportInitializer = tOptional(tObject({}));

packages/playwright-core/src/remote/playwrightServer.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ type ServerOptions = {
3939
preLaunchedBrowser?: Browser;
4040
preLaunchedAndroidDevice?: AndroidDevice;
4141
preLaunchedSocksProxy?: SocksProxy;
42-
debugController?: boolean;
4342
};
4443

4544
export class PlaywrightServer {
@@ -107,19 +106,6 @@ export class PlaywrightServer {
107106
const allowFSPaths = isExtension;
108107
launchOptions = filterLaunchOptions(launchOptions, allowFSPaths);
109108

110-
if (url.searchParams.has('debug-controller')) {
111-
if (!(this._options.debugController || isExtension))
112-
throw new Error('Debug controller is not enabled');
113-
return new PlaywrightConnection(
114-
controllerSemaphore,
115-
ws,
116-
true,
117-
this._playwright,
118-
async () => { throw new Error('shouldnt be used'); },
119-
id,
120-
);
121-
}
122-
123109
if (isExtension) {
124110
const connectFilter = url.searchParams.get('connect');
125111
if (connectFilter) {
@@ -135,6 +121,16 @@ export class PlaywrightServer {
135121
);
136122
}
137123

124+
if (url.searchParams.has('debug-controller')) {
125+
return new PlaywrightConnection(
126+
controllerSemaphore,
127+
ws,
128+
true,
129+
this._playwright,
130+
async () => { throw new Error('shouldnt be used'); },
131+
id,
132+
);
133+
}
138134
return new PlaywrightConnection(
139135
reuseBrowserSemaphore,
140136
ws,

packages/playwright-core/src/server/debugController.ts

Lines changed: 15 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import { unsafeLocatorOrSelectorAsSelector } from '../utils/isomorphic/locatorPa
2424
import { generateCode } from './codegen/language';
2525
import { collapseActions } from './recorder/recorderUtils';
2626
import { JavaScriptLanguageGenerator } from './codegen/javascript';
27-
import { Frame } from './frames';
28-
import { Page } from './page';
2927

3028
import type { Language } from '../utils';
3129
import type { BrowserContext } from './browserContext';
@@ -44,8 +42,7 @@ export class DebugController extends SdkObject {
4442
SetModeRequested: 'setModeRequested',
4543
};
4644

47-
private _reportState = false;
48-
private _disposeListeners = new Set<() => void>();
45+
private _trackHierarchyListener: InstrumentationListener | undefined;
4946
private _playwright: Playwright;
5047
_sdkLanguage: Language = 'javascript';
5148
_generateAutoExpect = false;
@@ -64,40 +61,25 @@ export class DebugController extends SdkObject {
6461
}
6562

6663
setReportStateChanged(enabled: boolean) {
67-
if (this._reportState === enabled)
68-
return;
69-
this._reportState = enabled;
70-
if (enabled) {
71-
const listener: InstrumentationListener = {
72-
onPageOpen: page => {
73-
this._emitSnapshot(false);
74-
const handleNavigation = () => this._emitSnapshot(false);
75-
page.mainFrame().on(Frame.Events.InternalNavigation, handleNavigation);
76-
const dispose = () => page.mainFrame().off(Frame.Events.InternalNavigation, handleNavigation);
77-
this._disposeListeners.add(dispose);
78-
page.on(Page.Events.Close, () => this._disposeListeners.delete(dispose));
79-
},
64+
if (enabled && !this._trackHierarchyListener) {
65+
this._trackHierarchyListener = {
66+
onPageOpen: () => this._emitSnapshot(false),
8067
onPageClose: () => this._emitSnapshot(false),
81-
onBrowserClose: () => {
82-
this._emitSnapshot(false);
83-
},
8468
};
85-
this._playwright.instrumentation.addListener(listener, null);
86-
this._disposeListeners.add(() => this._playwright.instrumentation.removeListener(listener));
69+
this._playwright.instrumentation.addListener(this._trackHierarchyListener, null);
8770
this._emitSnapshot(true);
88-
} else {
89-
for (const dispose of this._disposeListeners)
90-
dispose();
91-
this._disposeListeners.clear();
71+
} else if (!enabled && this._trackHierarchyListener) {
72+
this._playwright.instrumentation.removeListener(this._trackHierarchyListener);
73+
this._trackHierarchyListener = undefined;
9274
}
9375
}
9476

95-
async setRecorderMode(progress: Progress, params: { mode: Mode, testIdAttributeName?: string, generateAutoExpect?: boolean, browserId?: string }) {
77+
async setRecorderMode(progress: Progress, params: { mode: Mode, testIdAttributeName?: string, generateAutoExpect?: boolean }) {
9678
await progress.race(this._closeBrowsersWithoutPages());
9779
this._generateAutoExpect = !!params.generateAutoExpect;
9880

9981
if (params.mode === 'none') {
100-
for (const recorder of await progress.race(this._allRecorders(params.browserId))) {
82+
for (const recorder of await progress.race(this._allRecorders())) {
10183
recorder.hideHighlightedSelector();
10284
recorder.setMode('none');
10385
}
@@ -115,14 +97,11 @@ export class DebugController extends SdkObject {
11597
}
11698
// Update test id attribute.
11799
if (params.testIdAttributeName) {
118-
for (const page of this._playwright.allPages()) {
119-
if (params.browserId && page.browserContext._browser.guid !== params.browserId)
120-
continue;
100+
for (const page of this._playwright.allPages())
121101
page.browserContext.selectors().setTestIdAttributeName(params.testIdAttributeName);
122-
}
123102
}
124103
// Toggle the mode.
125-
for (const recorder of await progress.race(this._allRecorders(params.browserId))) {
104+
for (const recorder of await progress.race(this._allRecorders())) {
126105
recorder.hideHighlightedSelector();
127106
recorder.setMode(params.mode);
128107
}
@@ -154,13 +133,6 @@ export class DebugController extends SdkObject {
154133
recorder.resume();
155134
}
156135

157-
async closeBrowser(progress: Progress, id: string, reason?: string) {
158-
const browser = this._playwright.allBrowsers().find(b => b.guid === id);
159-
if (!browser)
160-
return;
161-
await progress.race(browser.close({ reason }));
162-
}
163-
164136
kill() {
165137
gracefullyProcessExitDoNotHang(0);
166138
}
@@ -169,28 +141,13 @@ export class DebugController extends SdkObject {
169141
const pageCount = this._playwright.allPages().length;
170142
if (initial && !pageCount)
171143
return;
172-
this.emit(DebugController.Events.StateChanged, {
173-
pageCount,
174-
browsers: this._playwright.allBrowsers().map(browser => ({
175-
id: browser.guid,
176-
name: browser.options.name,
177-
channel: browser.options.channel,
178-
contexts: browser.contexts().map(context => ({
179-
pages: context.pages().map(page => ({
180-
url: page.mainFrame().url(),
181-
}))
182-
}))
183-
}))
184-
});
144+
this.emit(DebugController.Events.StateChanged, { pageCount });
185145
}
186146

187-
private async _allRecorders(browserId?: string): Promise<Recorder[]> {
147+
private async _allRecorders(): Promise<Recorder[]> {
188148
const contexts = new Set<BrowserContext>();
189-
for (const page of this._playwright.allPages()) {
190-
if (browserId && page.browserContext._browser.guid !== browserId)
191-
continue;
149+
for (const page of this._playwright.allPages())
192150
contexts.add(page.browserContext);
193-
}
194151
const recorders = await Promise.all([...contexts].map(c => Recorder.forContext(c, { omitCallTracking: true })));
195152
const nonNullRecorders = recorders.filter(Boolean) as Recorder[];
196153
for (const recorder of recorders)

packages/playwright-core/src/server/dispatchers/debugControllerDispatcher.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ export class DebugControllerDispatcher extends Dispatcher<DebugController, chann
7878
this._object.kill();
7979
}
8080

81-
async closeBrowser(params: channels.DebugControllerCloseBrowserParams, progress: Progress) {
82-
await this._object.closeBrowser(progress, params.id, params.reason);
83-
}
84-
8581
override _onDispose() {
8682
eventsHelper.removeEventListeners(this._listeners);
8783
this._object.dispose();

packages/playwright-core/src/server/utils/wsServer.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,8 @@ export class WSServer {
106106
const url = new URL('http://localhost' + (request.url || ''));
107107
const id = String(++lastConnectionId);
108108
debugLogger.log('server', `[${id}] serving connection: ${request.url}`);
109-
try {
110-
const connection = this._delegate.onConnection(request, url, ws, id);
111-
(ws as any)[kConnectionSymbol] = connection;
112-
} catch (error) {
113-
debugLogger.log('server', `[${id}] connection error: ${error}`);
114-
ws.close(1011, String(error));
115-
}
109+
const connection = this._delegate.onConnection(request, url, ws, id);
110+
(ws as any)[kConnectionSymbol] = connection;
116111
});
117112

118113
return wsEndpoint;

0 commit comments

Comments
 (0)