Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate src/NetworkManager to TypeScript #5774

Merged
merged 1 commit into from Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/FrameManager.ts
Expand Up @@ -20,7 +20,7 @@ import {Events} from './Events';
import {ExecutionContext, EVALUATION_SCRIPT_URL} from './ExecutionContext';
import {LifecycleWatcher, PuppeteerLifeCycleEvent} from './LifecycleWatcher';
import {DOMWorld, WaitForSelectorOptions} from './DOMWorld';
import {NetworkManager} from './NetworkManager';
import {NetworkManager, Response} from './NetworkManager';
import {TimeoutSettings} from './TimeoutSettings';
import {CDPSession} from './Connection';
import {JSHandle, ElementHandle} from './JSHandle';
Expand All @@ -31,7 +31,7 @@ const UTILITY_WORLD_NAME = '__puppeteer_utility_world__';
export class FrameManager extends EventEmitter {
_client: CDPSession;
_page: Puppeteer.Page;
_networkManager: Puppeteer.NetworkManager;
_networkManager: NetworkManager;
_timeoutSettings: TimeoutSettings;
_frames = new Map<string, Frame>();
_contextIdToContext = new Map<number, ExecutionContext>();
Expand Down Expand Up @@ -70,11 +70,11 @@ export class FrameManager extends EventEmitter {
]);
}

networkManager(): Puppeteer.NetworkManager {
networkManager(): NetworkManager {
return this._networkManager;
}

async navigateFrame(frame: Frame, url: string, options: {referer?: string; timeout?: number; waitUntil?: PuppeteerLifeCycleEvent|PuppeteerLifeCycleEvent[]} = {}): Promise<Puppeteer.Response | null> {
async navigateFrame(frame: Frame, url: string, options: {referer?: string; timeout?: number; waitUntil?: PuppeteerLifeCycleEvent|PuppeteerLifeCycleEvent[]} = {}): Promise<Response | null> {
assertNoLegacyNavigationOptions(options);
const {
referer = this._networkManager.extraHTTPHeaders()['referer'],
Expand Down Expand Up @@ -110,7 +110,7 @@ export class FrameManager extends EventEmitter {
}
}

async waitForFrameNavigation(frame: Frame, options: {timeout?: number; waitUntil?: PuppeteerLifeCycleEvent|PuppeteerLifeCycleEvent[]} = {}): Promise<Puppeteer.Response | null> {
async waitForFrameNavigation(frame: Frame, options: {timeout?: number; waitUntil?: PuppeteerLifeCycleEvent|PuppeteerLifeCycleEvent[]} = {}): Promise<Response | null> {
assertNoLegacyNavigationOptions(options);
const {
waitUntil = ['load'],
Expand Down Expand Up @@ -333,11 +333,11 @@ export class Frame {
this._parentFrame._childFrames.add(this);
}

async goto(url: string, options: {referer?: string; timeout?: number; waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[]}): Promise<Puppeteer.Response | null> {
async goto(url: string, options: {referer?: string; timeout?: number; waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[]}): Promise<Response | null> {
return await this._frameManager.navigateFrame(this, url, options);
}

async waitForNavigation(options: {timeout?: number; waitUntil?: PuppeteerLifeCycleEvent|PuppeteerLifeCycleEvent[]}): Promise<Puppeteer.Response | null> {
async waitForNavigation(options: {timeout?: number; waitUntil?: PuppeteerLifeCycleEvent|PuppeteerLifeCycleEvent[]}): Promise<Response | null> {
return await this._frameManager.waitForFrameNavigation(this, options);
}

Expand Down
8 changes: 4 additions & 4 deletions src/LifecycleWatcher.ts
Expand Up @@ -18,6 +18,7 @@ import {helper, assert, PuppeteerEventListener} from './helper';
import {Events} from './Events';
import {TimeoutError} from './Errors';
import {FrameManager, Frame} from './FrameManager';
import {Request, Response} from './NetworkManager';

export type PuppeteerLifeCycleEvent = 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2';
type ProtocolLifeCycleEvent = 'load' | 'DOMContentLoaded' | 'networkIdle' | 'networkAlmostIdle';
Expand All @@ -35,7 +36,7 @@ export class LifecycleWatcher {
_frameManager: FrameManager;
_frame: Frame;
_timeout: number;
_navigationRequest?: Puppeteer.Request;
_navigationRequest?: Request;
_eventListeners: PuppeteerEventListener[];
_initialLoaderId: string;

Expand Down Expand Up @@ -72,7 +73,6 @@ export class LifecycleWatcher {
this._frame = frame;
this._initialLoaderId = frame._loaderId;
this._timeout = timeout;
/** @type {?Puppeteer.Request} */
this._navigationRequest = null;
this._eventListeners = [
helper.addEventListener(frameManager._client, Events.CDPSession.Disconnected, () => this._terminate(new Error('Navigation failed because browser has disconnected!'))),
Expand Down Expand Up @@ -101,7 +101,7 @@ export class LifecycleWatcher {
this._checkLifecycleComplete();
}

_onRequest(request: Puppeteer.Request): void {
_onRequest(request: Request): void {
if (request.frame() !== this._frame || !request.isNavigationRequest())
return;
this._navigationRequest = request;
Expand All @@ -115,7 +115,7 @@ export class LifecycleWatcher {
this._checkLifecycleComplete();
}

navigationResponse(): Puppeteer.Response | null {
navigationResponse(): Response | null {
return this._navigationRequest ? this._navigationRequest.response() : null;
}

Expand Down