Skip to content

Commit

Permalink
refactor: Pass FrameManager to NetworkManager constructor (#4907)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s authored and aslushnikov committed Sep 5, 2019
1 parent 73fd7ff commit c2651c2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
3 changes: 1 addition & 2 deletions lib/FrameManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class FrameManager extends EventEmitter {
super();
this._client = client;
this._page = page;
this._networkManager = new NetworkManager(client, ignoreHTTPSErrors);
this._networkManager.setFrameManager(this);
this._networkManager = new NetworkManager(client, ignoreHTTPSErrors, this);
this._timeoutSettings = timeoutSettings;
/** @type {!Map<string, !Frame>} */
this._frames = new Map();
Expand Down
14 changes: 4 additions & 10 deletions lib/NetworkManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ const {Events} = require('./Events');
class NetworkManager extends EventEmitter {
/**
* @param {!Puppeteer.CDPSession} client
* @param {!Puppeteer.FrameManager} frameManager
*/
constructor(client, ignoreHTTPSErrors) {
constructor(client, ignoreHTTPSErrors, frameManager) {
super();
this._client = client;
this._ignoreHTTPSErrors = ignoreHTTPSErrors;
this._frameManager = null;
this._frameManager = frameManager;
/** @type {!Map<string, !Request>} */
this._requestIdToRequest = new Map();
/** @type {!Map<string, !Protocol.Network.requestWillBeSentPayload>} */
Expand Down Expand Up @@ -60,13 +61,6 @@ class NetworkManager extends EventEmitter {
await this._client.send('Security.setIgnoreCertificateErrors', {ignore: true});
}

/**
* @param {!Puppeteer.FrameManager} frameManager
*/
setFrameManager(frameManager) {
this._frameManager = frameManager;
}

/**
* @param {?{username: string, password: string}} credentials
*/
Expand Down Expand Up @@ -234,7 +228,7 @@ class NetworkManager extends EventEmitter {
redirectChain = request._redirectChain;
}
}
const frame = event.frameId && this._frameManager ? this._frameManager.frame(event.frameId) : null;
const frame = event.frameId ? this._frameManager.frame(event.frameId) : null;
const request = new Request(this._client, frame, interceptionId, this._userRequestInterceptionEnabled, event, redirectChain);
this._requestIdToRequest.set(event.requestId, request);
this.emit(Events.NetworkManager.Request, request);
Expand Down

0 comments on commit c2651c2

Please sign in to comment.