refactor: use InitializationStatus consistently (#10192)

This commit is contained in:
Alex Rudenko 2023-05-17 10:13:17 +02:00 committed by GitHub
parent 5a5e4d46a3
commit dab77d0c06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 8 deletions

View File

@ -361,7 +361,7 @@ export class CDPBrowser extends BrowserBase {
}; };
#onAttachedToTarget = async (target: Target) => { #onAttachedToTarget = async (target: Target) => {
if (await target._initializedPromise) { if ((await target._initializedPromise) === InitializationStatus.SUCCESS) {
this.emit(BrowserEmittedEvents.TargetCreated, target); this.emit(BrowserEmittedEvents.TargetCreated, target);
target target
.browserContext() .browserContext()
@ -372,7 +372,7 @@ export class CDPBrowser extends BrowserBase {
#onDetachedFromTarget = async (target: Target): Promise<void> => { #onDetachedFromTarget = async (target: Target): Promise<void> => {
target._initializedPromise.resolve(InitializationStatus.ABORTED); target._initializedPromise.resolve(InitializationStatus.ABORTED);
target._isClosedPromise.resolve(); target._isClosedPromise.resolve();
if (await target._initializedPromise) { if ((await target._initializedPromise) === InitializationStatus.SUCCESS) {
this.emit(BrowserEmittedEvents.TargetDestroyed, target); this.emit(BrowserEmittedEvents.TargetDestroyed, target);
target target
.browserContext() .browserContext()
@ -432,7 +432,8 @@ export class CDPBrowser extends BrowserBase {
if (!target) { if (!target) {
throw new Error(`Missing target for page (id = ${targetId})`); throw new Error(`Missing target for page (id = ${targetId})`);
} }
const initialized = await target._initializedPromise; const initialized =
(await target._initializedPromise) === InitializationStatus.SUCCESS;
if (!initialized) { if (!initialized) {
throw new Error(`Failed to create target for page (id = ${targetId})`); throw new Error(`Failed to create target for page (id = ${targetId})`);
} }
@ -453,7 +454,9 @@ export class CDPBrowser extends BrowserBase {
return Array.from( return Array.from(
this.#targetManager.getAvailableTargets().values() this.#targetManager.getAvailableTargets().values()
).filter(target => { ).filter(target => {
return target._initializedPromise.resolved(); return (
target._initializedPromise.value() === InitializationStatus.SUCCESS
);
}); });
} }

View File

@ -249,13 +249,13 @@ export class PageTarget extends Target {
protected override _initialize(): void { protected override _initialize(): void {
this._initializedPromise this._initializedPromise
.then(async success => { .then(async result => {
if (!success) { if (result === InitializationStatus.ABORTED) {
return false; return;
} }
const opener = this.opener(); const opener = this.opener();
if (!(opener instanceof PageTarget)) { if (!(opener instanceof PageTarget)) {
return true; return;
} }
if (!opener || !opener.pagePromise || this.type() !== 'page') { if (!opener || !opener.pagePromise || this.type() !== 'page') {
return true; return true;