mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
refactor: use InitializationStatus consistently (#10192)
This commit is contained in:
parent
5a5e4d46a3
commit
dab77d0c06
@ -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
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user