chore: add waitForInitiallyDiscoveredTargets (#10745)
This commit is contained in:
parent
fc08a7dd54
commit
77ffbba141
@ -64,7 +64,8 @@ export class CDPBrowser extends BrowserBase {
|
|||||||
process?: ChildProcess,
|
process?: ChildProcess,
|
||||||
closeCallback?: BrowserCloseCallback,
|
closeCallback?: BrowserCloseCallback,
|
||||||
targetFilterCallback?: TargetFilterCallback,
|
targetFilterCallback?: TargetFilterCallback,
|
||||||
isPageTargetCallback?: IsPageTargetCallback
|
isPageTargetCallback?: IsPageTargetCallback,
|
||||||
|
waitForInitiallyDiscoveredTargets = true
|
||||||
): Promise<CDPBrowser> {
|
): Promise<CDPBrowser> {
|
||||||
const browser = new CDPBrowser(
|
const browser = new CDPBrowser(
|
||||||
product,
|
product,
|
||||||
@ -75,7 +76,8 @@ export class CDPBrowser extends BrowserBase {
|
|||||||
process,
|
process,
|
||||||
closeCallback,
|
closeCallback,
|
||||||
targetFilterCallback,
|
targetFilterCallback,
|
||||||
isPageTargetCallback
|
isPageTargetCallback,
|
||||||
|
waitForInitiallyDiscoveredTargets
|
||||||
);
|
);
|
||||||
await browser._attach();
|
await browser._attach();
|
||||||
return browser;
|
return browser;
|
||||||
@ -111,7 +113,8 @@ export class CDPBrowser extends BrowserBase {
|
|||||||
process?: ChildProcess,
|
process?: ChildProcess,
|
||||||
closeCallback?: BrowserCloseCallback,
|
closeCallback?: BrowserCloseCallback,
|
||||||
targetFilterCallback?: TargetFilterCallback,
|
targetFilterCallback?: TargetFilterCallback,
|
||||||
isPageTargetCallback?: IsPageTargetCallback
|
isPageTargetCallback?: IsPageTargetCallback,
|
||||||
|
waitForInitiallyDiscoveredTargets = true
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
product = product || 'chrome';
|
product = product || 'chrome';
|
||||||
@ -137,7 +140,8 @@ export class CDPBrowser extends BrowserBase {
|
|||||||
this.#targetManager = new ChromeTargetManager(
|
this.#targetManager = new ChromeTargetManager(
|
||||||
connection,
|
connection,
|
||||||
this.#createTarget,
|
this.#createTarget,
|
||||||
this.#targetFilterCallback
|
this.#targetFilterCallback,
|
||||||
|
waitForInitiallyDiscoveredTargets
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
this.#defaultContext = new CDPBrowserContext(this.#connection, this);
|
this.#defaultContext = new CDPBrowserContext(this.#connection, this);
|
||||||
|
@ -84,16 +84,19 @@ export class ChromeTargetManager extends EventEmitter implements TargetManager {
|
|||||||
|
|
||||||
#initializeDeferred = Deferred.create<void>();
|
#initializeDeferred = Deferred.create<void>();
|
||||||
#targetsIdsForInit = new Set<string>();
|
#targetsIdsForInit = new Set<string>();
|
||||||
|
#waitForInitiallyDiscoveredTargets = true;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
connection: Connection,
|
connection: Connection,
|
||||||
targetFactory: TargetFactory,
|
targetFactory: TargetFactory,
|
||||||
targetFilterCallback?: TargetFilterCallback
|
targetFilterCallback?: TargetFilterCallback,
|
||||||
|
waitForInitiallyDiscoveredTargets = true
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
this.#connection = connection;
|
this.#connection = connection;
|
||||||
this.#targetFilterCallback = targetFilterCallback;
|
this.#targetFilterCallback = targetFilterCallback;
|
||||||
this.#targetFactory = targetFactory;
|
this.#targetFactory = targetFactory;
|
||||||
|
this.#waitForInitiallyDiscoveredTargets = waitForInitiallyDiscoveredTargets;
|
||||||
|
|
||||||
this.#connection.on('Target.targetCreated', this.#onTargetCreated);
|
this.#connection.on('Target.targetCreated', this.#onTargetCreated);
|
||||||
this.#connection.on('Target.targetDestroyed', this.#onTargetDestroyed);
|
this.#connection.on('Target.targetDestroyed', this.#onTargetDestroyed);
|
||||||
@ -111,6 +114,9 @@ export class ChromeTargetManager extends EventEmitter implements TargetManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#storeExistingTargetsForInit = () => {
|
#storeExistingTargetsForInit = () => {
|
||||||
|
if (!this.#waitForInitiallyDiscoveredTargets) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (const [
|
for (const [
|
||||||
targetId,
|
targetId,
|
||||||
targetInfo,
|
targetInfo,
|
||||||
|
Loading…
Reference in New Issue
Block a user