revert subscription logic
This commit is contained in:
parent
c5aad394be
commit
27f8be2fe0
|
|
@ -69,8 +69,7 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel>
|
|||
_closeWasCalled = false;
|
||||
private _closeReason: string | undefined;
|
||||
private _harRouters: HarRouter[] = [];
|
||||
|
||||
_mockingProxies = new Set<MockingProxy>();
|
||||
private _mockingProxies = new Set<MockingProxy>();
|
||||
|
||||
static from(context: channels.BrowserContextChannel): BrowserContext {
|
||||
return (context as any)._object;
|
||||
|
|
@ -229,6 +228,8 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel>
|
|||
await route._innerContinue(true /* isFallback */).catch(() => {});
|
||||
}
|
||||
|
||||
private _onRouteListener = (route: network.Route) => this._onRoute(route);
|
||||
|
||||
async _onWebSocketRoute(webSocketRoute: network.WebSocketRoute) {
|
||||
const routeHandler = this._webSocketRoutes.find(route => route.matches(webSocketRoute.url()));
|
||||
if (routeHandler)
|
||||
|
|
@ -244,6 +245,11 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel>
|
|||
await bindingCall.call(func);
|
||||
}
|
||||
|
||||
_subscribeToMockingProxy(mockingProxy: MockingProxy) {
|
||||
this._mockingProxies.add(mockingProxy);
|
||||
mockingProxy.on(Events.MockingProxy.Route, this._onRouteListener);
|
||||
}
|
||||
|
||||
setDefaultNavigationTimeout(timeout: number | undefined) {
|
||||
this._timeoutSettings.setDefaultNavigationTimeout(timeout);
|
||||
this._wrapApiCall(async () => {
|
||||
|
|
@ -465,7 +471,9 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel>
|
|||
this._disposeHarRouters();
|
||||
this.tracing._resetStackCounter();
|
||||
this.emit(Events.BrowserContext.Close, this);
|
||||
this._mockingProxies.forEach(p => p.uninstall(this));
|
||||
this._mockingProxies.forEach(p => {
|
||||
p.off(Events.MockingProxy.Route, this._onRouteListener);
|
||||
});
|
||||
}
|
||||
|
||||
async [Symbol.asyncDispose]() {
|
||||
|
|
|
|||
|
|
@ -94,4 +94,8 @@ export const Events = {
|
|||
Console: 'console',
|
||||
Window: 'window',
|
||||
},
|
||||
|
||||
MockingProxy: {
|
||||
Route: 'rooute',
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -17,40 +17,23 @@ import * as network from './network';
|
|||
import type * as channels from '@protocol/channels';
|
||||
import { ChannelOwner } from './channelOwner';
|
||||
import { APIRequestContext } from './fetch';
|
||||
import type { BrowserContext } from './browserContext';
|
||||
|
||||
export class MockingProxy extends ChannelOwner<channels.MockingProxyChannel> {
|
||||
private _port: number;
|
||||
private _requestContext: APIRequestContext;
|
||||
private _contexts = new Set<BrowserContext>();
|
||||
|
||||
constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.MockingProxyInitializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
|
||||
this._port = initializer.port;
|
||||
this._requestContext = APIRequestContext.from(initializer.requestContext);
|
||||
const requestContext = APIRequestContext.from(initializer.requestContext);
|
||||
|
||||
this._channel.on('route', (params: channels.MockingProxyRouteEvent) => {
|
||||
const route = network.Route.from(params.route);
|
||||
route._context = this._requestContext;
|
||||
for (const context of this._contexts) {
|
||||
context._onRoute(route);
|
||||
for (const page of context.pages())
|
||||
page._onRoute(route);
|
||||
}
|
||||
route._context = requestContext;
|
||||
this.emit('route', route);
|
||||
});
|
||||
}
|
||||
|
||||
install(context: BrowserContext): void {
|
||||
context._mockingProxies.add(this);
|
||||
this._contexts.add(context);
|
||||
}
|
||||
|
||||
uninstall(context: BrowserContext): void {
|
||||
context._mockingProxies.delete(this);
|
||||
this._contexts.delete(context);
|
||||
}
|
||||
|
||||
async setInterceptionPatterns(params: channels.MockingProxySetInterceptionPatternsParams) {
|
||||
await this._channel.setInterceptionPatterns(params);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import { rootTestType } from './common/testType';
|
|||
import type { ContextReuseMode } from './common/config';
|
||||
import type { ApiCallData, ClientInstrumentation, ClientInstrumentationListener } from '../../playwright-core/src/client/clientInstrumentation';
|
||||
import type { MockingProxy } from '../../playwright-core/src/client/mockingProxy';
|
||||
import type { BrowserContext as BrowserContextImpl } from '../../playwright-core/src/client/browserContext';
|
||||
import { currentTestInfo } from './common/globals';
|
||||
import type { LocalUtils } from 'playwright-core/lib/client/localUtils';
|
||||
export { expect } from './matchers/expect';
|
||||
|
|
@ -369,8 +370,9 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
|
|||
size: typeof video === 'string' ? undefined : video.size,
|
||||
}
|
||||
} : {};
|
||||
const context = await browser.newContext({ ...videoOptions, ...options });
|
||||
_mockingProxy?.install(context as any);
|
||||
const context = await browser.newContext({ ...videoOptions, ...options }) as BrowserContextImpl;
|
||||
if (_mockingProxy)
|
||||
context._subscribeToMockingProxy(_mockingProxy);
|
||||
const contextData: { pagesWithVideo: Page[] } = { pagesWithVideo: [] };
|
||||
contexts.set(context, contextData);
|
||||
if (captureVideo)
|
||||
|
|
|
|||
Loading…
Reference in a new issue