From 826fe42c48fe0a5fb49c62f1b87387638a6635c8 Mon Sep 17 00:00:00 2001 From: JoelEinbinder Date: Mon, 12 Mar 2018 11:34:33 -0700 Subject: [PATCH] fix(Network): response.ok should be true for file:// urls (#2152) --- lib/NetworkManager.js | 4 ++-- lib/Page.js | 15 ++++++++------- lib/externs.d.ts | 6 ++++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/NetworkManager.js b/lib/NetworkManager.js index c0f7cbc0b94..ba54e62fd41 100644 --- a/lib/NetworkManager.js +++ b/lib/NetworkManager.js @@ -537,7 +537,7 @@ class Response { * @return {boolean} */ ok() { - return this._status >= 200 && this._status <= 299; + return this._status === 0 || (this._status >= 200 && this._status <= 299); } /** @@ -772,4 +772,4 @@ const statusTexts = { '511': 'Network Authentication Required', }; -module.exports = NetworkManager; +module.exports = {Request, Response, NetworkManager}; diff --git a/lib/Page.js b/lib/Page.js index b2f61f76834..c30f42d5e51 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -17,7 +17,7 @@ const fs = require('fs'); const EventEmitter = require('events'); const mime = require('mime'); -const NetworkManager = require('./NetworkManager'); +const {NetworkManager} = require('./NetworkManager'); const NavigatorWatcher = require('./NavigatorWatcher'); const Dialog = require('./Dialog'); const EmulationManager = require('./EmulationManager'); @@ -478,11 +478,12 @@ class Page extends EventEmitter { /** * @param {string} url * @param {!Object=} options - * @return {!Promise} + * @return {!Promise} */ async goto(url, options = {}) { const referrer = this._networkManager.extraHTTPHeaders()['referer']; + /** @type {Map} */ const requests = new Map(); const eventListeners = [ helper.addEventListener(this._networkManager, NetworkManager.Events.Request, request => { @@ -526,7 +527,7 @@ class Page extends EventEmitter { /** * @param {!Object=} options - * @return {!Promise} + * @return {!Promise} */ async reload(options) { const [response] = await Promise.all([ @@ -538,7 +539,7 @@ class Page extends EventEmitter { /** * @param {!Object=} options - * @return {!Promise} + * @return {!Promise} */ async waitForNavigation(options = {}) { const mainFrame = this._frameManager.mainFrame(); @@ -556,7 +557,7 @@ class Page extends EventEmitter { /** * @param {!Object=} options - * @return {!Promise} + * @return {!Promise} */ async goBack(options) { return this._go(-1, options); @@ -564,7 +565,7 @@ class Page extends EventEmitter { /** * @param {!Object=} options - * @return {!Promise} + * @return {!Promise} */ async goForward(options) { return this._go(+1, options); @@ -572,7 +573,7 @@ class Page extends EventEmitter { /** * @param {!Object=} options - * @return {!Promise} + * @return {!Promise} */ async _go(delta, options) { const history = await this._client.send('Page.getNavigationHistory'); diff --git a/lib/externs.d.ts b/lib/externs.d.ts index 112861ae0c7..be6c175dbc2 100644 --- a/lib/externs.d.ts +++ b/lib/externs.d.ts @@ -7,7 +7,7 @@ import {Mouse as RealMouse, Keyboard as RealKeyboard, Touchscreen as RealTouchsc import {Frame as RealFrame, FrameManager as RealFrameManager} from './FrameManager.js'; import {JSHandle as RealJSHandle, ExecutionContext as RealExecutionContext} from './ExecutionContext.js'; import * as RealElementHandle from './ElementHandle.js'; -import * as RealNetworkManager from './NetworkManager.js'; +import { NetworkManager as RealNetworkManager, Request as RealRequest, Response as RealResponse } from './NetworkManager.js'; import * as child_process from 'child_process'; export as namespace Puppeteer; @@ -25,7 +25,9 @@ export class NetworkManager extends RealNetworkManager {} export class ElementHandle extends RealElementHandle {} export class JSHandle extends RealJSHandle {} export class ExecutionContext extends RealExecutionContext {} -export class Page extends RealPage {} +export class Page extends RealPage { } +export class Response extends RealResponse { } +export class Request extends RealRequest { } export interface ConnectionTransport extends NodeJS.EventEmitter { send(string);