mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
refactor: move target updates to the target manager (#10189)
This commit is contained in:
parent
2e289a7e87
commit
372d12172b
@ -374,22 +374,11 @@ export class CDPBrowser extends BrowserBase {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#onTargetChanged = ({
|
#onTargetChanged = ({target}: {target: Target}): void => {
|
||||||
target,
|
this.emit(BrowserEmittedEvents.TargetChanged, target);
|
||||||
targetInfo,
|
target
|
||||||
}: {
|
.browserContext()
|
||||||
target: Target;
|
.emit(BrowserContextEmittedEvents.TargetChanged, target);
|
||||||
targetInfo: Protocol.Target.TargetInfo;
|
|
||||||
}): void => {
|
|
||||||
const previousURL = target.url();
|
|
||||||
const wasInitialized = target._isInitialized;
|
|
||||||
target._targetInfoChanged(targetInfo);
|
|
||||||
if (wasInitialized && previousURL !== target.url()) {
|
|
||||||
this.emit(BrowserEmittedEvents.TargetChanged, target);
|
|
||||||
target
|
|
||||||
.browserContext()
|
|
||||||
.emit(BrowserContextEmittedEvents.TargetChanged, target);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#onTargetDiscovered = (targetInfo: Protocol.Target.TargetInfo): void => {
|
#onTargetDiscovered = (targetInfo: Protocol.Target.TargetInfo): void => {
|
||||||
|
@ -263,10 +263,21 @@ export class ChromeTargetManager extends EventEmitter implements TargetManager {
|
|||||||
const target = this.#attachedTargetsByTargetId.get(
|
const target = this.#attachedTargetsByTargetId.get(
|
||||||
event.targetInfo.targetId
|
event.targetInfo.targetId
|
||||||
);
|
);
|
||||||
this.emit(TargetManagerEmittedEvents.TargetChanged, {
|
if (!target) {
|
||||||
target: target!,
|
return;
|
||||||
targetInfo: event.targetInfo,
|
}
|
||||||
});
|
const previousURL = target.url();
|
||||||
|
const wasInitialized = target._isInitialized;
|
||||||
|
|
||||||
|
target._targetInfoChanged(event.targetInfo);
|
||||||
|
|
||||||
|
if (wasInitialized && previousURL !== target.url()) {
|
||||||
|
this.emit(TargetManagerEmittedEvents.TargetChanged, {
|
||||||
|
target: target,
|
||||||
|
wasInitialized,
|
||||||
|
previousURL,
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#onAttachedToTarget = async (
|
#onAttachedToTarget = async (
|
||||||
|
@ -68,5 +68,8 @@ export const enum TargetManagerEmittedEvents {
|
|||||||
TargetDiscovered = 'targetDiscovered',
|
TargetDiscovered = 'targetDiscovered',
|
||||||
TargetAvailable = 'targetAvailable',
|
TargetAvailable = 'targetAvailable',
|
||||||
TargetGone = 'targetGone',
|
TargetGone = 'targetGone',
|
||||||
|
/**
|
||||||
|
* Emitted after a target has been initialized and whenever its URL changes.
|
||||||
|
*/
|
||||||
TargetChanged = 'targetChanged',
|
TargetChanged = 'targetChanged',
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user