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 = ({
|
||||
target,
|
||||
targetInfo,
|
||||
}: {
|
||||
target: Target;
|
||||
targetInfo: Protocol.Target.TargetInfo;
|
||||
}): void => {
|
||||
const previousURL = target.url();
|
||||
const wasInitialized = target._isInitialized;
|
||||
target._targetInfoChanged(targetInfo);
|
||||
if (wasInitialized && previousURL !== target.url()) {
|
||||
#onTargetChanged = ({target}: {target: Target}): void => {
|
||||
this.emit(BrowserEmittedEvents.TargetChanged, target);
|
||||
target
|
||||
.browserContext()
|
||||
.emit(BrowserContextEmittedEvents.TargetChanged, target);
|
||||
}
|
||||
};
|
||||
|
||||
#onTargetDiscovered = (targetInfo: Protocol.Target.TargetInfo): void => {
|
||||
|
@ -263,10 +263,21 @@ export class ChromeTargetManager extends EventEmitter implements TargetManager {
|
||||
const target = this.#attachedTargetsByTargetId.get(
|
||||
event.targetInfo.targetId
|
||||
);
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
const previousURL = target.url();
|
||||
const wasInitialized = target._isInitialized;
|
||||
|
||||
target._targetInfoChanged(event.targetInfo);
|
||||
|
||||
if (wasInitialized && previousURL !== target.url()) {
|
||||
this.emit(TargetManagerEmittedEvents.TargetChanged, {
|
||||
target: target!,
|
||||
targetInfo: event.targetInfo,
|
||||
target: target,
|
||||
wasInitialized,
|
||||
previousURL,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
#onAttachedToTarget = async (
|
||||
|
@ -68,5 +68,8 @@ export const enum TargetManagerEmittedEvents {
|
||||
TargetDiscovered = 'targetDiscovered',
|
||||
TargetAvailable = 'targetAvailable',
|
||||
TargetGone = 'targetGone',
|
||||
/**
|
||||
* Emitted after a target has been initialized and whenever its URL changes.
|
||||
*/
|
||||
TargetChanged = 'targetChanged',
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user