mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: refactor init to make sure it works with paused targets (#8710)
This commit is contained in:
parent
7580a1be01
commit
8477105e09
@ -22,7 +22,12 @@ import {Frame} from './FrameManager.js';
|
|||||||
import {HTTPRequest} from './HTTPRequest.js';
|
import {HTTPRequest} from './HTTPRequest.js';
|
||||||
import {HTTPResponse} from './HTTPResponse.js';
|
import {HTTPResponse} from './HTTPResponse.js';
|
||||||
import {FetchRequestId, NetworkEventManager} from './NetworkEventManager.js';
|
import {FetchRequestId, NetworkEventManager} from './NetworkEventManager.js';
|
||||||
import {debugError, isString} from './util.js';
|
import {
|
||||||
|
debugError,
|
||||||
|
isString,
|
||||||
|
createDeferredPromiseWithTimer,
|
||||||
|
DeferredPromise,
|
||||||
|
} from './util.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
@ -95,6 +100,7 @@ export class NetworkManager extends EventEmitter {
|
|||||||
download: -1,
|
download: -1,
|
||||||
latency: 0,
|
latency: 0,
|
||||||
};
|
};
|
||||||
|
#deferredInitPromise?: DeferredPromise<void>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
client: CDPSession,
|
client: CDPSession,
|
||||||
@ -131,13 +137,34 @@ export class NetworkManager extends EventEmitter {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async initialize(): Promise<void> {
|
/**
|
||||||
await this.#client.send('Network.enable');
|
* Initialize calls should avoid async dependencies between CDP calls as those
|
||||||
if (this.#ignoreHTTPSErrors) {
|
* might not resolve until after the target is resumed causing a deadlock.
|
||||||
await this.#client.send('Security.setIgnoreCertificateErrors', {
|
*/
|
||||||
ignore: true,
|
initialize(): Promise<void> {
|
||||||
});
|
if (this.#deferredInitPromise) {
|
||||||
|
return this.#deferredInitPromise.promise;
|
||||||
}
|
}
|
||||||
|
this.#deferredInitPromise = createDeferredPromiseWithTimer<void>(
|
||||||
|
'NetworkManager initialization timed out',
|
||||||
|
30000
|
||||||
|
);
|
||||||
|
const init = Promise.all([
|
||||||
|
this.#ignoreHTTPSErrors
|
||||||
|
? this.#client.send('Security.setIgnoreCertificateErrors', {
|
||||||
|
ignore: true,
|
||||||
|
})
|
||||||
|
: null,
|
||||||
|
this.#client.send('Network.enable'),
|
||||||
|
]);
|
||||||
|
init
|
||||||
|
.then(() => {
|
||||||
|
this.#deferredInitPromise?.resolve();
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
return this.#deferredInitPromise?.reject(err);
|
||||||
|
});
|
||||||
|
return this.#deferredInitPromise.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
async authenticate(credentials?: Credentials): Promise<void> {
|
async authenticate(credentials?: Credentials): Promise<void> {
|
||||||
|
Loading…
Reference in New Issue
Block a user