address comments

This commit is contained in:
Yury Semikhatsky 2024-08-13 10:35:59 -07:00
parent e942ad4869
commit e9014f2b6e
3 changed files with 8 additions and 7 deletions

View file

@ -47,7 +47,7 @@ export const kNoXServerRunningError = 'Looks like you launched a headed browser
export interface BrowserReadyState { export interface BrowserReadyState {
onBrowserOutput(message: string): void; onBrowserOutput(message: string): void;
onBrowserExit(): void; onBrowserExit(): void;
ready(): Promise<string|undefined>; waitUntilReady(): Promise<{ wsEndpoint?: string }>;
} }
export abstract class BrowserType extends SdkObject { export abstract class BrowserType extends SdkObject {
@ -250,7 +250,7 @@ export abstract class BrowserType extends SdkObject {
kill kill
}; };
progress.cleanupWhenAborted(() => closeOrKill(progress.timeUntilDeadline())); progress.cleanupWhenAborted(() => closeOrKill(progress.timeUntilDeadline()));
const wsEndpoint = await readyState?.ready(); const wsEndpoint = (await readyState?.waitUntilReady())?.wsEndpoint;
if (options.useWebSocket) { if (options.useWebSocket) {
transport = await WebSocketTransport.connect(progress, wsEndpoint!); transport = await WebSocketTransport.connect(progress, wsEndpoint!);
} else { } else {

View file

@ -369,8 +369,9 @@ class ChromiumReadyState implements BrowserReadyState {
onBrowserExit(): void { onBrowserExit(): void {
this._wsEndpoint.reject(new Error('Browser exited')); this._wsEndpoint.reject(new Error('Browser exited'));
} }
async ready(): Promise<string|undefined> { async waitUntilReady(): Promise<{ wsEndpoint?: string }> {
return this._wsEndpoint; const wsEndpoint = await this._wsEndpoint;
return { wsEndpoint };
} }
} }

View file

@ -104,11 +104,11 @@ class JugglerReadyState implements BrowserReadyState {
} }
onBrowserExit(): void { onBrowserExit(): void {
// Unblock launch when browser prematurely exits. // Unblock launch when browser prematurely exits.
this._jugglerPromise.resolve(); this._jugglerPromise.reject(new Error('Browser exited'));
} }
async ready(): Promise<string | undefined> { async waitUntilReady(): Promise<{ wsEndpoint?: string }> {
await this._jugglerPromise; await this._jugglerPromise;
return undefined; return { };
} }
} }