mirror of
https://github.com/microsoft/playwright.git
synced 2024-09-11 20:37:54 +03:00
fix: separate Selectors instance per Playwright object (#9529)
We used to share selectors for inprocess, remote and any internal playwright objects.
This commit is contained in:
parent
b391d525a9
commit
b383c6bf3c
@ -27,6 +27,7 @@ import { assert, headersObjectToArray, getUserAgent, monotonicTime } from '../ut
|
||||
import * as api from '../../types/types';
|
||||
import { kBrowserClosedError } from '../utils/errors';
|
||||
import { raceAgainstDeadline } from '../utils/async';
|
||||
import type { Playwright } from './playwright';
|
||||
|
||||
export interface BrowserServerLauncher {
|
||||
launchServer(options?: LaunchServerOptions): Promise<api.BrowserServer>;
|
||||
@ -43,6 +44,7 @@ export interface BrowserServer extends api.BrowserServer {
|
||||
export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel, channels.BrowserTypeInitializer> implements api.BrowserType {
|
||||
_serverLauncher?: BrowserServerLauncher;
|
||||
_contexts = new Set<BrowserContext>();
|
||||
_playwright!: Playwright;
|
||||
|
||||
// Instrumentation.
|
||||
_defaultContextOptions: BrowserContextOptions = {};
|
||||
@ -54,10 +56,6 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel, chann
|
||||
return (browserType as any)._object;
|
||||
}
|
||||
|
||||
constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.BrowserTypeInitializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
}
|
||||
|
||||
executablePath(): string {
|
||||
if (!this._initializer.executablePath)
|
||||
throw new Error('Browser is not supported on current platform');
|
||||
@ -172,6 +170,7 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel, chann
|
||||
closePipe();
|
||||
return;
|
||||
}
|
||||
playwright._setSelectors(this._playwright.selectors);
|
||||
browser = Browser.from(playwright._initializer.preLaunchedBrowser!);
|
||||
browser._logger = logger;
|
||||
browser._shouldCloseConnectionOnClose = true;
|
||||
|
@ -25,7 +25,7 @@ import { BrowserType } from './browserType';
|
||||
import { ChannelOwner } from './channelOwner';
|
||||
import { Electron } from './electron';
|
||||
import { Fetch } from './fetch';
|
||||
import { Selectors, SelectorsOwner, sharedSelectors } from './selectors';
|
||||
import { Selectors, SelectorsOwner } from './selectors';
|
||||
import { Size } from './types';
|
||||
const dnsLookupAsync = util.promisify(dns.lookup);
|
||||
|
||||
@ -46,7 +46,7 @@ export class Playwright extends ChannelOwner<channels.PlaywrightChannel, channel
|
||||
readonly firefox: BrowserType;
|
||||
readonly webkit: BrowserType;
|
||||
readonly devices: Devices;
|
||||
readonly selectors: Selectors;
|
||||
selectors: Selectors;
|
||||
readonly request: Fetch;
|
||||
readonly errors: { TimeoutError: typeof TimeoutError };
|
||||
private _sockets = new Map<string, net.Socket>();
|
||||
@ -56,14 +56,17 @@ export class Playwright extends ChannelOwner<channels.PlaywrightChannel, channel
|
||||
super(parent, type, guid, initializer);
|
||||
this.request = new Fetch(this);
|
||||
this.chromium = BrowserType.from(initializer.chromium);
|
||||
this.chromium._playwright = this;
|
||||
this.firefox = BrowserType.from(initializer.firefox);
|
||||
this.firefox._playwright = this;
|
||||
this.webkit = BrowserType.from(initializer.webkit);
|
||||
this.webkit._playwright = this;
|
||||
this._android = Android.from(initializer.android);
|
||||
this._electron = Electron.from(initializer.electron);
|
||||
this.devices = {};
|
||||
for (const { name, descriptor } of initializer.deviceDescriptors)
|
||||
this.devices[name] = descriptor;
|
||||
this.selectors = sharedSelectors;
|
||||
this.selectors = new Selectors();
|
||||
this.errors = { TimeoutError };
|
||||
|
||||
const selectorsOwner = SelectorsOwner.from(initializer.selectors);
|
||||
@ -75,6 +78,13 @@ export class Playwright extends ChannelOwner<channels.PlaywrightChannel, channel
|
||||
});
|
||||
}
|
||||
|
||||
_setSelectors(selectors: Selectors) {
|
||||
const selectorsOwner = SelectorsOwner.from(this._initializer.selectors);
|
||||
this.selectors._removeChannel(selectorsOwner);
|
||||
this.selectors = selectors;
|
||||
this.selectors._addChannel(selectorsOwner);
|
||||
}
|
||||
|
||||
_enablePortForwarding(redirectPortForTest?: number) {
|
||||
this._redirectPortForTest = redirectPortForTest;
|
||||
this._channel.on('socksRequested', ({ uid, host, port }) => this._onSocksRequested(uid, host, port));
|
||||
|
@ -50,5 +50,3 @@ export class SelectorsOwner extends ChannelOwner<channels.SelectorsChannel, chan
|
||||
return (browser as any)._object;
|
||||
}
|
||||
}
|
||||
|
||||
export const sharedSelectors = new Selectors();
|
||||
|
Loading…
Reference in New Issue
Block a user