apply same for Browser
This commit is contained in:
parent
461818dfd2
commit
2e20ac19b2
|
|
@ -49,7 +49,7 @@ export class Browser extends ChannelOwner<channels.BrowserChannel> implements ap
|
||||||
constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.BrowserInitializer) {
|
constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.BrowserInitializer) {
|
||||||
super(parent, type, guid, initializer);
|
super(parent, type, guid, initializer);
|
||||||
this._name = initializer.name;
|
this._name = initializer.name;
|
||||||
this._channel.on('close', () => this._didClose());
|
this._channel.on('close', ({ reason }) => this._didClose(reason));
|
||||||
this._closedPromise = new Promise(f => this.once(Events.Browser.Disconnected, f));
|
this._closedPromise = new Promise(f => this.once(Events.Browser.Disconnected, f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,10 +136,9 @@ export class Browser extends ChannelOwner<channels.BrowserChannel> implements ap
|
||||||
}
|
}
|
||||||
|
|
||||||
async close(options: { reason?: string } = {}): Promise<void> {
|
async close(options: { reason?: string } = {}): Promise<void> {
|
||||||
this._closeReason = options.reason;
|
|
||||||
try {
|
try {
|
||||||
if (this._shouldCloseConnectionOnClose)
|
if (this._shouldCloseConnectionOnClose)
|
||||||
this._connection.close();
|
this._connection.close(options.reason);
|
||||||
else
|
else
|
||||||
await this._channel.close(options);
|
await this._channel.close(options);
|
||||||
await this._closedPromise;
|
await this._closedPromise;
|
||||||
|
|
@ -150,8 +149,9 @@ export class Browser extends ChannelOwner<channels.BrowserChannel> implements ap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_didClose() {
|
_didClose(reason?: string) {
|
||||||
this._isConnected = false;
|
this._isConnected = false;
|
||||||
|
this._closeReason = reason;
|
||||||
this.emit(Events.Browser.Disconnected, this);
|
this.emit(Events.Browser.Disconnected, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -608,7 +608,9 @@ scheme.BrowserInitializer = tObject({
|
||||||
version: tString,
|
version: tString,
|
||||||
name: tString,
|
name: tString,
|
||||||
});
|
});
|
||||||
scheme.BrowserCloseEvent = tOptional(tObject({}));
|
scheme.BrowserCloseEvent = tObject({
|
||||||
|
reason: tOptional(tString),
|
||||||
|
});
|
||||||
scheme.BrowserCloseParams = tObject({
|
scheme.BrowserCloseParams = tObject({
|
||||||
reason: tOptional(tString),
|
reason: tOptional(tString),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,7 @@ export abstract class Browser extends SdkObject {
|
||||||
context._browserClosed();
|
context._browserClosed();
|
||||||
if (this._defaultContext)
|
if (this._defaultContext)
|
||||||
this._defaultContext._browserClosed();
|
this._defaultContext._browserClosed();
|
||||||
this.emit(Browser.Events.Disconnected);
|
this.emit(Browser.Events.Disconnected, { reason: this._closeReason });
|
||||||
this.instrumentation.onBrowserClose(this);
|
this.instrumentation.onBrowserClose(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,11 +34,11 @@ export class BrowserDispatcher extends Dispatcher<Browser, channels.BrowserChann
|
||||||
|
|
||||||
constructor(scope: BrowserTypeDispatcher, browser: Browser) {
|
constructor(scope: BrowserTypeDispatcher, browser: Browser) {
|
||||||
super(scope, browser, 'Browser', { version: browser.version(), name: browser.options.name });
|
super(scope, browser, 'Browser', { version: browser.version(), name: browser.options.name });
|
||||||
this.addObjectListener(Browser.Events.Disconnected, () => this._didClose());
|
this.addObjectListener(Browser.Events.Disconnected, ({ reason }) => this._didClose(reason));
|
||||||
}
|
}
|
||||||
|
|
||||||
_didClose() {
|
_didClose(reason?: string) {
|
||||||
this._dispatchEvent('close');
|
this._dispatchEvent('close', { reason });
|
||||||
this._dispose();
|
this._dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1131,7 +1131,9 @@ export interface BrowserChannel extends BrowserEventTarget, Channel {
|
||||||
startTracing(params: BrowserStartTracingParams, metadata?: CallMetadata): Promise<BrowserStartTracingResult>;
|
startTracing(params: BrowserStartTracingParams, metadata?: CallMetadata): Promise<BrowserStartTracingResult>;
|
||||||
stopTracing(params?: BrowserStopTracingParams, metadata?: CallMetadata): Promise<BrowserStopTracingResult>;
|
stopTracing(params?: BrowserStopTracingParams, metadata?: CallMetadata): Promise<BrowserStopTracingResult>;
|
||||||
}
|
}
|
||||||
export type BrowserCloseEvent = {};
|
export type BrowserCloseEvent = {
|
||||||
|
reason?: string,
|
||||||
|
};
|
||||||
export type BrowserCloseParams = {
|
export type BrowserCloseParams = {
|
||||||
reason?: string,
|
reason?: string,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1009,6 +1009,8 @@ Browser:
|
||||||
events:
|
events:
|
||||||
|
|
||||||
close:
|
close:
|
||||||
|
parameters:
|
||||||
|
reason: string?
|
||||||
|
|
||||||
ConsoleMessage:
|
ConsoleMessage:
|
||||||
type: mixin
|
type: mixin
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue