Skip to content

Commit 83d5165

Browse files
authored
chore(bidi): use bidi- channels with playwright.chromium (#37702)
1 parent c85932f commit 83d5165

31 files changed

+57
-67
lines changed

packages/playwright-client/types/types.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16290,7 +16290,6 @@ export type AndroidKey =
1629016290

1629116291
export const _electron: Electron;
1629216292
export const _android: Android;
16293-
export const _bidiChromium: BrowserType;
1629416293

1629516294
// This is required to not export everything by default. See https://github.com/Microsoft/TypeScript/issues/19545#issuecomment-340490459
1629616295
export {};

packages/playwright-core/src/browserServerImpl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ import type { WebSocketEventEmitter } from './utilsBundle';
3232
import type { Browser } from './server/browser';
3333

3434
export class BrowserServerLauncherImpl implements BrowserServerLauncher {
35-
private _browserName: 'chromium' | 'firefox' | 'webkit' | '_bidiChromium';
35+
private _browserName: 'chromium' | 'firefox' | 'webkit';
3636

37-
constructor(browserName: 'chromium' | 'firefox' | 'webkit' | '_bidiChromium') {
37+
constructor(browserName: 'chromium' | 'firefox' | 'webkit') {
3838
this._browserName = browserName;
3939
}
4040

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import type { BrowserContextOptions, LaunchOptions } from 'playwright-core';
2929
export class Playwright extends ChannelOwner<channels.PlaywrightChannel> {
3030
readonly _android: Android;
3131
readonly _electron: Electron;
32-
readonly _bidiChromium: BrowserType;
3332
readonly chromium: BrowserType;
3433
readonly firefox: BrowserType;
3534
readonly webkit: BrowserType;
@@ -57,8 +56,6 @@ export class Playwright extends ChannelOwner<channels.PlaywrightChannel> {
5756
this._android._playwright = this;
5857
this._electron = Electron.from(initializer.electron);
5958
this._electron._playwright = this;
60-
this._bidiChromium = BrowserType.from(initializer._bidiChromium);
61-
this._bidiChromium._playwright = this;
6259
this.devices = this._connection.localUtils()?.devices ?? {};
6360
this.selectors = new Selectors(this._connection._platform);
6461
this.errors = { TimeoutError };
@@ -69,7 +66,7 @@ export class Playwright extends ChannelOwner<channels.PlaywrightChannel> {
6966
}
7067

7168
private _browserTypes(): BrowserType[] {
72-
return [this.chromium, this.firefox, this.webkit, this._bidiChromium];
69+
return [this.chromium, this.firefox, this.webkit];
7370
}
7471

7572
_preLaunchedBrowser(): Browser {

packages/playwright-core/src/inProcessFactory.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export function createInProcessPlaywright(): PlaywrightAPI {
4242
playwrightAPI.firefox._serverLauncher = new BrowserServerLauncherImpl('firefox');
4343
playwrightAPI.webkit._serverLauncher = new BrowserServerLauncherImpl('webkit');
4444
playwrightAPI._android._serverLauncher = new AndroidServerLauncherImpl();
45-
playwrightAPI._bidiChromium._serverLauncher = new BrowserServerLauncherImpl('_bidiChromium');
4645

4746
// Switch to async dispatch after we got Playwright object.
4847
dispatcherConnection.onmessage = message => setImmediate(() => clientConnection.dispatch(message));

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,6 @@ scheme.PlaywrightInitializer = tObject({
377377
chromium: tChannel(['BrowserType']),
378378
firefox: tChannel(['BrowserType']),
379379
webkit: tChannel(['BrowserType']),
380-
_bidiChromium: tChannel(['BrowserType']),
381380
android: tChannel(['Android']),
382381
electron: tChannel(['Electron']),
383382
utils: tOptional(tChannel(['LocalUtils'])),

packages/playwright-core/src/server/bidi/bidiChromium.ts

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

3434
export class BidiChromium extends BrowserType {
3535
constructor(parent: SdkObject) {
36-
super(parent, '_bidiChromium');
36+
super(parent, 'chromium');
3737
}
3838

3939
override async connectToTransport(transport: ConnectionTransport, options: BrowserOptions, browserLogsCollector: RecentLogsCollector): Promise<BidiBrowser> {

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,38 @@ import type { SdkObject } from '../instrumentation';
4444
import type { Progress } from '../progress';
4545
import type { ProtocolError } from '../protocolError';
4646
import type { ConnectionTransport, ProtocolRequest } from '../transport';
47+
import type { BrowserContext } from '../browserContext';
4748
import type * as types from '../types';
49+
import type * as channels from '@protocol/channels';
4850
import type http from 'http';
4951
import type stream from 'stream';
5052

5153
const ARTIFACTS_FOLDER = path.join(os.tmpdir(), 'playwright-artifacts-');
5254

5355
export class Chromium extends BrowserType {
5456
private _devtools: CRDevTools | undefined;
57+
private _bidiChromium: BrowserType;
5558

56-
constructor(parent: SdkObject) {
59+
constructor(parent: SdkObject, bidiChromium: BrowserType) {
5760
super(parent, 'chromium');
61+
this._bidiChromium = bidiChromium;
5862

5963
if (debugMode() === 'inspector')
6064
this._devtools = this._createDevTools();
6165
}
6266

67+
override launch(progress: Progress, options: types.LaunchOptions, protocolLogger?: types.ProtocolLogger): Promise<Browser> {
68+
if (options.channel?.startsWith('bidi-'))
69+
return this._bidiChromium.launch(progress, options, protocolLogger);
70+
return super.launch(progress, options, protocolLogger);
71+
}
72+
73+
override async launchPersistentContext(progress: Progress, userDataDir: string, options: channels.BrowserTypeLaunchPersistentContextOptions & { cdpPort?: number, internalIgnoreHTTPSErrors?: boolean, socksProxyPort?: number }): Promise<BrowserContext> {
74+
if (options.channel?.startsWith('bidi-'))
75+
return this._bidiChromium.launchPersistentContext(progress, userDataDir, options);
76+
return super.launchPersistentContext(progress, userDataDir, options);
77+
}
78+
6379
override async connectOverCDP(progress: Progress, endpointURL: string, options: { slowMo?: number, headers?: types.HeadersArray }) {
6480
return await this._connectOverCDPInternal(progress, endpointURL, options);
6581
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { Dispatcher } from './dispatcher';
2525
import { FrameDispatcher } from './frameDispatcher';
2626
import { APIRequestContextDispatcher, RequestDispatcher, ResponseDispatcher, RouteDispatcher } from './networkDispatchers';
2727
import { BindingCallDispatcher, PageDispatcher, WorkerDispatcher } from './pageDispatcher';
28-
import { CRBrowserContext } from '../chromium/crBrowser';
28+
import { CRBrowser, CRBrowserContext } from '../chromium/crBrowser';
2929
import { serializeError } from '../errors';
3030
import { TracingDispatcher } from './tracingDispatcher';
3131
import { WebSocketRouteDispatcher } from './webSocketRouteDispatcher';
@@ -136,7 +136,7 @@ export class BrowserContextDispatcher extends Dispatcher<BrowserContext, channel
136136
};
137137
context.dialogManager.addDialogHandler(this._dialogHandler);
138138

139-
if (context._browser.options.name === 'chromium') {
139+
if (context._browser.options.name === 'chromium' && this._object._browser instanceof CRBrowser) {
140140
for (const serviceWorker of (context as CRBrowserContext).serviceWorkers())
141141
this._dispatchEvent('serviceWorker', { worker: new WorkerDispatcher(this, serviceWorker) });
142142
this.addObjectListener(CRBrowserContext.CREvents.ServiceWorker, serviceWorker => this._dispatchEvent('serviceWorker', { worker: new WorkerDispatcher(this, serviceWorker) }));

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,11 @@ export class PlaywrightDispatcher extends Dispatcher<Playwright, channels.Playwr
5353
const chromium = new BrowserTypeDispatcher(scope, playwright.chromium, denyLaunch);
5454
const firefox = new BrowserTypeDispatcher(scope, playwright.firefox, denyLaunch);
5555
const webkit = new BrowserTypeDispatcher(scope, playwright.webkit, denyLaunch);
56-
const _bidiChromium = new BrowserTypeDispatcher(scope, playwright._bidiChromium, denyLaunch);
5756
const android = new AndroidDispatcher(scope, playwright.android);
5857
const initializer: channels.PlaywrightInitializer = {
5958
chromium,
6059
firefox,
6160
webkit,
62-
_bidiChromium,
6361
android,
6462
electron: new ElectronDispatcher(scope, playwright.electron, denyLaunch),
6563
utils: playwright.options.isServer ? undefined : new LocalUtilsDispatcher(scope, playwright),

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export class Playwright extends SdkObject {
4242
readonly electron: Electron;
4343
readonly firefox: BrowserType;
4444
readonly webkit: BrowserType;
45-
readonly _bidiChromium: BrowserType;
4645
readonly options: PlaywrightOptions;
4746
readonly debugController: DebugController;
4847
private _allPages = new Set<Page>();
@@ -58,8 +57,7 @@ export class Playwright extends SdkObject {
5857
onPageOpen: page => this._allPages.add(page),
5958
onPageClose: page => this._allPages.delete(page),
6059
}, null);
61-
this.chromium = new Chromium(this);
62-
this._bidiChromium = new BidiChromium(this);
60+
this.chromium = new Chromium(this, new BidiChromium(this));
6361
this.firefox = new Firefox(this, new BidiFirefox(this));
6462
this.webkit = new WebKit(this);
6563
this.electron = new Electron(this);

0 commit comments

Comments
 (0)