Skip to content

Commit

Permalink
refactor: use InitializationStatus consistently (#10192)
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN committed May 17, 2023
1 parent 5a5e4d4 commit dab77d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
11 changes: 7 additions & 4 deletions packages/puppeteer-core/src/common/Browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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})`);
}
Expand All @@ -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
);
});
}

Expand Down
8 changes: 4 additions & 4 deletions packages/puppeteer-core/src/common/Target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit dab77d0

Please sign in to comment.