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) => {
if (await target._initializedPromise) {
if ((await target._initializedPromise) === InitializationStatus.SUCCESS) {
this.emit(BrowserEmittedEvents.TargetCreated, target);
target
.browserContext()
@ -372,7 +372,7 @@ export class CDPBrowser extends BrowserBase {
#onDetachedFromTarget = async (target: Target): Promise<void> => {
target._initializedPromise.resolve(InitializationStatus.ABORTED);
target._isClosedPromise.resolve();
if (await target._initializedPromise) {
if ((await target._initializedPromise) === InitializationStatus.SUCCESS) {
this.emit(BrowserEmittedEvents.TargetDestroyed, target);
target
.browserContext()
@ -432,7 +432,8 @@ export class CDPBrowser extends BrowserBase {
if (!target) {
throw new Error(`Missing target for page (id = ${targetId})`);
}
const initialized = await target._initializedPromise;
const initialized =
(await target._initializedPromise) === InitializationStatus.SUCCESS;
if (!initialized) {
throw new Error(`Failed to create target for page (id = ${targetId})`);
}
@ -453,7 +454,9 @@ export class CDPBrowser extends BrowserBase {
return Array.from(
this.#targetManager.getAvailableTargets().values()
).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 {
this._initializedPromise
.then(async success => {
if (!success) {
return false;
.then(async result => {
if (result === InitializationStatus.ABORTED) {
return;
}
const opener = this.opener();
if (!(opener instanceof PageTarget)) {
return true;
return;
}
if (!opener || !opener.pagePromise || this.type() !== 'page') {
return true;