Skip to content

Commit

Permalink
chore: we need the bind the client as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightning00Blade committed Apr 19, 2024
1 parent eeed3a7 commit 27cb6e9
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions packages/puppeteer-core/src/cdp/NetworkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,15 @@ export class NetworkManager extends EventEmitter<NetworkManagerEvents> {
#userAgentMetadata?: Protocol.Emulation.UserAgentMetadata;

readonly #handlers = [
['Fetch.requestPaused', this.#onRequestPaused.bind(this)],
['Fetch.authRequired', this.#onAuthRequired.bind(this)],
['Network.requestWillBeSent', this.#onRequestWillBeSent.bind(this)],
[
'Network.requestServedFromCache',
this.#onRequestServedFromCache.bind(this),
],
['Network.responseReceived', this.#onResponseReceived.bind(this)],
['Network.loadingFinished', this.#onLoadingFinished.bind(this)],
['Network.loadingFailed', this.#onLoadingFailed.bind(this)],
[
'Network.responseReceivedExtraInfo',
this.#onResponseReceivedExtraInfo.bind(this),
],
[CDPSessionEvent.Disconnected, this.#removeClient.bind(this)],
['Fetch.requestPaused', this.#onRequestPaused],
['Fetch.authRequired', this.#onAuthRequired],
['Network.requestWillBeSent', this.#onRequestWillBeSent],
['Network.requestServedFromCache', this.#onRequestServedFromCache],
['Network.responseReceived', this.#onResponseReceived],
['Network.loadingFinished', this.#onLoadingFinished],
['Network.loadingFailed', this.#onLoadingFailed],
['Network.responseReceivedExtraInfo', this.#onResponseReceivedExtraInfo],
[CDPSessionEvent.Disconnected, this.#removeClient],
] as const;

#clients = new Map<CDPSession, DisposableStack>();
Expand All @@ -109,7 +103,9 @@ export class NetworkManager extends EventEmitter<NetworkManagerEvents> {
const clientEmitter = subscriptions.use(new EventEmitter(client));

for (const [event, handler] of this.#handlers) {
clientEmitter.on(event, handler as any);
clientEmitter.on(event, (arg: any) => {
return handler.bind(this)(client, arg);
});
}

await Promise.all([
Expand Down

0 comments on commit 27cb6e9

Please sign in to comment.